2 Unix SMB/Netbios implementation.
4 replacement routines for broken systems
5 Copyright (C) Andrew Tridgell 1992-1997
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
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
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 extern int DEBUGLEVEL;
27 void replace_dummy(void)
31 /****************************************************************************
32 a replacement strlen() that returns int for solaris
33 ****************************************************************************/
44 /*******************************************************************
45 ftruncate for operating systems that don't have it
46 ********************************************************************/
47 int ftruncate(int f,long l)
55 return fcntl(f, F_FREESP, &fl);
61 /****************************************************************************
62 Mips version of strstr doesn't seem to work correctly.
63 There is a #define in includes.h to redirect calls to this function.
64 ****************************************************************************/
65 char *Strstr(char *s, char *p)
69 while ( *s != '\0' ) {
70 if ( strncmp(s, p, len) == 0 )
77 #endif /* REPLACE_STRSTR */
81 /*******************************************************************
82 a mktime() replacement for those who don't have it - contributed by
83 C.A. Lademann <cal@zls.com>
84 ********************************************************************/
86 #define HOUR 60*MINUTE
89 time_t Mktime(struct tm *t)
93 int mon [] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
99 epoch = (t->tm_year - 70) * YEAR +
100 (t->tm_year / 4 - 70 / 4 - t->tm_year / 100) * DAY;
105 for(i = 0; i < t->tm_mon; i++) {
106 epoch += mon [m] * DAY;
107 if(m == 1 && y % 4 == 0 && (y % 100 != 0 || y % 400 == 0))
116 epoch += (t->tm_mday - 1) * DAY;
117 epoch += t->tm_hour * HOUR + t->tm_min * MINUTE + t->tm_sec;
119 if((u = localtime(&epoch)) != NULL) {
120 t->tm_sec = u->tm_sec;
121 t->tm_min = u->tm_min;
122 t->tm_hour = u->tm_hour;
123 t->tm_mday = u->tm_mday;
124 t->tm_mon = u->tm_mon;
125 t->tm_year = u->tm_year;
126 t->tm_wday = u->tm_wday;
127 t->tm_yday = u->tm_yday;
128 t->tm_isdst = u->tm_isdst;
130 memcpy(t->tm_name, u->tm_name, LTZNMAX);
136 #endif /* REPLACE_MKTIME */
140 #ifdef REPLACE_RENAME
141 /* Rename a file. (from libiberty in GNU binutils) */
142 int rename (zfrom, zto)
146 if (link (zfrom, zto) < 0)
151 || link (zfrom, zto) < 0)
154 return unlink (zfrom);
159 #ifdef REPLACE_INNETGR
161 * Search for a match in a netgroup. This replaces it on broken systems.
163 int InNetGr(char *group,char *host,char *user,char *dom)
165 char *hst, *usr, *dm;
168 while (getnetgrent(&hst, &usr, &dm))
169 if (((host == 0) || (hst == 0) || !strcmp(host, hst)) &&
170 ((user == 0) || (usr == 0) || !strcmp(user, usr)) &&
171 ((dom == 0) || (dm == 0) || !strcmp(dom, dm))) {
183 #include <sys/types.h>
188 #define NULL (void *)0
191 /****************************************************************************
192 some systems don't have an initgroups call
193 ****************************************************************************/
194 int initgroups(char *name,gid_t id)
197 /* yikes! no SETGROUPS or INITGROUPS? how can this work? */
200 gid_t grouplst[NGROUPS_MAX];
207 while (i < NGROUPS_MAX &&
208 ((g = (struct group *)getgrent()) != (struct group *)NULL))
214 while (gr && (*gr != (char)NULL)) {
215 if (strcmp(name,gr) == 0) {
216 grouplst[i] = g->gr_gid;
225 return(setgroups(i,grouplst));
231 #if (defined(SecureWare) && defined(SCO))
232 /* This is needed due to needing the nap() function but we don't want
233 to include the Xenix libraries since that will break other things...
234 BTW: system call # 0x0c28 is the same as calling nap() */
235 long nap(long milliseconds) {
236 return syscall(0x0c28, milliseconds);
243 /*******************************************************************
244 a wrapper around memcpy for diagnostic purposes
245 ********************************************************************/
246 void *memcpy_wrapped(void *d,void *s,int l,char *fname,int line)
248 if (l>64 && (((int)d)%4) != (((int)s)%4))
249 DEBUG(4,("Misaligned memcpy(0x%X,0x%X,%d) at %s(%d)\n",d,s,l,fname,line));
251 return(xx_old_memcpy(d,s,l));
253 return(memcpy(d,s,l));
256 #define memcpy(d,s,l) memcpy_wrapped(d,s,l,__FILE__,__LINE__)