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 as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
28 int len = strlen(s) + 1;
29 char *ret = (char *)malloc(len);
37 char *getcwd(char *buf, int size)
45 pid_t waitpid(pid_t pid, int *statptr, int options)
48 return wait4(pid, statptr, options, NULL);
50 /* If wait4 is also not available, try wait3 for SVR3 variants */
51 /* Less ideal because can't actually request a specific pid */
52 /* At least the WNOHANG option is supported */
53 /* Code borrowed from apache fragment written by dwd@bell-labs.com */
54 int tmp_pid, dummystat;;
55 if (kill(pid, 0) == -1) {
61 while (((tmp_pid = wait3(statptr, options, 0)) != pid) &&
62 (tmp_pid != -1) && (tmp_pid != 0) && (pid != -1))
71 void *memmove(void *dest, const void *src, size_t n)
73 bcopy((char *) src, (char *) dest, n);
80 * Find the first ocurrence in @p s of any character in @p accept.
84 char *strpbrk(const char *s, const char *accept)
87 const char *a = accept;
89 if (*a++ == *s) return (char *)s;
101 * Like strncpy but does not 0 fill the buffer and always null
104 * @param bufsize is the size of the destination buffer.
106 * @return index of the terminating byte.
108 size_t strlcpy(char *d, const char *s, size_t bufsize)
110 size_t len = strlen(s);
124 * Like strncat() but does not 0 fill the buffer and always null
127 * @param bufsize length of the buffer, which should be one more than
128 * the maximum resulting string length.
130 size_t strlcat(char *d, const char *s, size_t bufsize)
132 size_t len1 = strlen(d);
133 size_t len2 = strlen(s);
134 size_t ret = len1 + len2;
136 if (len1 < bufsize - 1) {
137 if (len2 >= bufsize - len1)
138 len2 = bufsize - len1 - 1;
139 memcpy(d+len1, s, len2);
146 /* some systems don't take the 2nd argument */
147 int sys_gettimeofday(struct timeval *tv)
149 #ifdef HAVE_GETTIMEOFDAY_TZ
150 return gettimeofday(tv, NULL);
152 return gettimeofday(tv);