2 * Reimplementations of standard functions for platforms that don't have them.
4 * Copyright (C) 1998 Andrew Tridgell
5 * Copyright (C) 2002 Martin Pool
6 * Copyright (C) 2004, 2005, 2006 Wayne Davison
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 3 as
10 * published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, visit the http://fsf.org website.
26 int len = strlen(s) + 1;
27 char *ret = (char *)malloc(len);
35 char *getcwd(char *buf, int size)
43 pid_t waitpid(pid_t pid, int *statptr, int options)
46 return wait4(pid, statptr, options, NULL);
48 /* If wait4 is also not available, try wait3 for SVR3 variants */
49 /* Less ideal because can't actually request a specific pid */
50 /* At least the WNOHANG option is supported */
51 /* Code borrowed from apache fragment written by dwd@bell-labs.com */
52 int tmp_pid, dummystat;;
53 if (kill(pid, 0) == -1) {
59 while (((tmp_pid = wait3(statptr, options, 0)) != pid) &&
60 (tmp_pid != -1) && (tmp_pid != 0) && (pid != -1))
69 void *memmove(void *dest, const void *src, size_t n)
71 bcopy((char *) src, (char *) dest, n);
78 * Find the first ocurrence in @p s of any character in @p accept.
82 char *strpbrk(const char *s, const char *accept)
85 const char *a = accept;
87 if (*a++ == *s) return (char *)s;
99 * Like strncpy but does not 0 fill the buffer and always null
102 * @param bufsize is the size of the destination buffer.
104 * @return index of the terminating byte.
106 size_t strlcpy(char *d, const char *s, size_t bufsize)
108 size_t len = strlen(s);
122 * Like strncat() but does not 0 fill the buffer and always null
125 * @param bufsize length of the buffer, which should be one more than
126 * the maximum resulting string length.
128 size_t strlcat(char *d, const char *s, size_t bufsize)
130 size_t len1 = strlen(d);
131 size_t len2 = strlen(s);
132 size_t ret = len1 + len2;
134 if (len1 < bufsize - 1) {
135 if (len2 >= bufsize - len1)
136 len2 = bufsize - len1 - 1;
137 memcpy(d+len1, s, len2);
144 /* some systems don't take the 2nd argument */
145 int sys_gettimeofday(struct timeval *tv)
147 #ifdef HAVE_GETTIMEOFDAY_TZ
148 return gettimeofday(tv, NULL);
150 return gettimeofday(tv);