/[osn-commons]/trunk/plibc/lib/string.c
ViewVC logotype

Contents of /trunk/plibc/lib/string.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 51 - (show annotations)
Fri Aug 16 18:34:43 2024 UTC (7 months, 2 weeks ago) by rakinar2
File MIME type: text/x-c
File size: 2734 byte(s)
feat: add basic utilities and more system calls

1 #include "string.h"
2 #include "errno.h"
3
4 size_t
5 strlen (const char *str)
6 {
7 size_t len = 0;
8
9 while (str[len])
10 len++;
11
12 return len;
13 }
14
15 static const char *errno_lut[] = {
16 [0] = "Success",
17 [EPERM] = "Operation not permitted",
18 [ENOENT] = "No such file or directory",
19 [ESRCH] = "No such process",
20 [EINTR] = "Interrupted system call",
21 [EIO] = "I/O error",
22 [ENXIO] = "No such device or address",
23 [E2BIG] = "Argument list too long",
24 [ENOEXEC] = "Exec format error",
25 [EBADF] = "Bad file number",
26 [ECHILD] = "No child processes",
27 [EAGAIN] = "Try again",
28 [ENOMEM] = "Out of memory",
29 [EACCES] = "Permission denied",
30 [EFAULT] = "Bad address",
31 [ENOTBLK] = "Block device required",
32 [EBUSY] = "Device or resource busy",
33 [EEXIST] = "File exists",
34 [EXDEV] = "Cross-device link",
35 [ENODEV] = "No such device",
36 [ENOTDIR] = "Not a directory",
37 [EISDIR] = "Is a directory",
38 [EINVAL] = "Invalid argument",
39 [ENFILE] = "File table overflow",
40 [EMFILE] = "Too many open files",
41 [ENOTTY] = "Not a typewriter",
42 [ETXTBSY] = "Text file busy",
43 [EFBIG] = "File too large",
44 [ENOSPC] = "No space left on device",
45 [ESPIPE] = "Illegal seek",
46 [EROFS] = "Read-only file system",
47 [EMLINK] = "Too many links",
48 [EPIPE] = "Broken pipe",
49 [EDOM] = "Math argument out of domain of func",
50 [ERANGE] = "Math result not representable",
51 [EDEADLK] = "Resource deadlock would occur",
52 [ENAMETOOLONG] = "File name too long",
53 [ENOLCK] = "No record locks available",
54 [ENOSYS] = "Function not implemented",
55 [ENOTEMPTY] = "Directory not empty",
56 [ELOOP] = "Too many symbolic links encountered",
57 [ENOMSG] = "No message of desired type",
58 [EIDRM] = "Identifier removed",
59 [ECHRNG] = "Channel number out of range",
60 [EL2NSYNC] = "Level 2 not synchronized",
61 [EL3HLT] = "Level 3 halted",
62 [EL3RST] = "Level 3 reset",
63 [ELNRNG] = "Link number out of range",
64 [EUNATCH] = "Protocol driver not attached",
65 [ENOCSI] = "No CSI structure available",
66 [EL2HLT] = "Level 2 halted",
67 [EBADE] = "Invalid exchange",
68 [EBADR] = "Invalid request descriptor",
69 [EXFULL] = "Exchange full",
70 [ENOANO] = "No anode",
71 [EBADRQC] = "Invalid request code",
72 [EBADSLT] = "Invalid slot",
73 [EBFONT] = "Bad font file format",
74 };
75
76 const char *
77 strerror (int errnum)
78 {
79 if (errnum < 0
80 || (size_t) (errnum) >= sizeof (errno_lut) / sizeof (errno_lut[0]))
81 return "Unknown error";
82
83 return errno_lut[errnum];
84 }
85
86 void *
87 memcpy (void *dest, const void *src, size_t n)
88 {
89 for (size_t i = 0; i < n; i++)
90 ((char *) dest)[i] = ((const char *) src)[i];
91
92 return dest;
93 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26