2 Copyright (C) Andrew Tridgell 1998
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 compatibility functions - replacing functions for platforms that don't
30 int l = strlen(s) + 1;
31 char *ret = (char *)malloc(l);
39 char *getcwd(char *buf, int size)
47 pid_t waitpid(pid_t pid, int *statptr, int options)
49 return wait4(pid, statptr, options, NULL);
55 void *memmove(void *dest, const void *src, size_t n)
63 /* Find the first ocurrence in S of any character in ACCEPT.
66 char *strpbrk(const char *s, const char *accept)
69 const char *a = accept;
71 if (*a++ == *s) return (char *)s;
80 #ifdef REPLACE_INET_NTOA
81 char *rep_inet_ntoa(struct in_addr ip)
83 unsigned char *p = (unsigned char *)&ip.s_addr;
86 slprintf(buf, 18, "%d.%d.%d.%d",
87 (int)p[0], (int)p[1], (int)p[2], (int)p[3]);
89 slprintf(buf, 18, "%d.%d.%d.%d",
90 (int)p[3], (int)p[2], (int)p[1], (int)p[0]);
97 /* like strncpy but does not 0 fill the buffer and always null
98 terminates. bufsize is the size of the destination buffer */
99 size_t strlcpy(char *d, const char *s, size_t bufsize)
101 size_t len = strlen(s);
103 if (len >= bufsize) len = bufsize-1;
111 /* like strncat but does not 0 fill the buffer and always null
112 terminates. bufsize is the length of the buffer, which should
113 be one more than the maximum resulting string length */
114 size_t strlcat(char *d, const char *s, size_t bufsize)
116 size_t len1 = strlen(d);
117 size_t len2 = strlen(s);
118 size_t ret = len1 + len2;
120 if (len1+len2 >= bufsize) {
121 len2 = bufsize - (len1+1);
124 memcpy(d+len1, s, len2);