2 Copyright (C) Andrew Tridgell 1998
3 Copyright (C) 2002 by Martin Pool
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 * Reimplementations of standard functions for platforms that don't
35 int l = strlen(s) + 1;
36 char *ret = (char *)malloc(l);
44 char *getcwd(char *buf, int size)
52 pid_t waitpid(pid_t pid, int *statptr, int options)
55 return wait4(pid, statptr, options, NULL);
57 /* If wait4 is also not available, try wait3 for SVR3 variants */
58 /* Less ideal because can't actually request a specific pid */
59 /* At least the WNOHANG option is supported */
60 /* Code borrowed from apache fragment written by dwd@bell-labs.com */
61 int tmp_pid, dummystat;;
62 if (kill(pid, 0) == -1) {
68 while (((tmp_pid = wait3(statptr, options, 0)) != pid) &&
69 (tmp_pid != -1) && (tmp_pid != 0) && (pid != -1))
78 void *memmove(void *dest, const void *src, size_t n)
80 bcopy((char *) src, (char *) dest, n);
87 * Find the first ocurrence in @p s of any character in @p accept.
91 char *strpbrk(const char *s, const char *accept)
94 const char *a = accept;
96 if (*a++ == *s) return (char *)s;
108 * Like strncpy but does not 0 fill the buffer and always null
111 * @param bufsize is the size of the destination buffer.
113 * @return index of the terminating byte.
115 size_t strlcpy(char *d, const char *s, size_t bufsize)
117 size_t len = strlen(s);
131 * Like strncat() but does not 0 fill the buffer and always null
134 * @param bufsize length of the buffer, which should be one more than
135 * the maximum resulting string length.
137 size_t strlcat(char *d, const char *s, size_t bufsize)
139 size_t len1 = strlen(d);
140 size_t len2 = strlen(s);
141 size_t ret = len1 + len2;
143 if (len1 < bufsize - 1) {
144 if (len2 >= bufsize - len1)
145 len2 = bufsize - len1 - 1;
146 memcpy(d+len1, s, len2);
153 /* some systems don't take the 2nd argument */
154 int sys_gettimeofday(struct timeval *tv)
156 #ifdef HAVE_GETTIMEOFDAY_TZ
157 return gettimeofday(tv, NULL);
159 return gettimeofday(tv);