version 1.5, 1997/10/07 23:39:34 |
version 1.6, 1998/06/26 21:21:01 |
|
|
*/ |
*/ |
|
|
#ifndef lint |
#ifndef lint |
|
#if 0 |
static char RCSid[] = |
static char RCSid[] = |
|
"$From: common.c,v 6.82 1998/03/23 23:27:33 michaelc Exp $"; |
|
#else |
|
static char RCSid[] = |
"$OpenBSD$"; |
"$OpenBSD$"; |
|
#endif |
|
|
static char sccsid[] = "@(#)common.c"; |
static char sccsid[] = "@(#)common.c"; |
|
|
|
|
#if defined(NEED_UTIME_H) |
#if defined(NEED_UTIME_H) |
#include <utime.h> |
#include <utime.h> |
#endif /* defined(NEED_UTIME_H) */ |
#endif /* defined(NEED_UTIME_H) */ |
|
#include <sys/socket.h> |
|
#include <sys/wait.h> |
|
|
/* |
/* |
* Variables common to both client and server |
* Variables common to both client and server |
|
|
|
|
if (!progname) { |
if (!progname) { |
progname = strdup(argv[0]); |
progname = strdup(argv[0]); |
if (cp = strrchr(progname, '/')) |
if ((cp = strrchr(progname, '/'))) |
progname = cp + 1; |
progname = cp + 1; |
} |
} |
} |
} |
|
|
for (i = 0; i < argc; i++) |
for (i = 0; i < argc; i++) |
realargv[i] = strdup(argv[i]); |
realargv[i] = strdup(argv[i]); |
|
|
#if defined(SETARGS) && !defined(__OpenBSD__) |
#if defined(SETARGS) |
setargs_settup(argc, argv, envp); |
setargs_settup(argc, argv, envp); |
#endif /* SETARGS */ |
#endif /* SETARGS */ |
|
|
|
|
/* |
/* |
* Non-line-oriented remote read. |
* Non-line-oriented remote read. |
*/ |
*/ |
|
int |
readrem(p, space) |
readrem(p, space) |
char *p; |
char *p; |
register int space; |
register int space; |
|
|
/* |
/* |
* Try to avoid getpwuid() call. |
* Try to avoid getpwuid() call. |
*/ |
*/ |
if (lastuid == uid && buf[0] && buf[0] != ':') |
if (lastuid == uid && buf[0] != '\0' && buf[0] != ':') |
return(buf); |
return(buf); |
|
|
lastuid = uid; |
lastuid = uid; |
|
|
/* |
/* |
* Try to avoid getgrgid() call. |
* Try to avoid getgrgid() call. |
*/ |
*/ |
if (lastgid == gid && buf[0] && buf[0] != ':') |
if (lastgid == gid && buf[0] != '\0' && buf[0] != ':') |
return(buf); |
return(buf); |
|
|
lastgid = gid; |
lastgid = gid; |
|
|
*s3 = '/'; |
*s3 = '/'; |
s2 = pw->pw_dir; |
s2 = pw->pw_dir; |
} |
} |
for (s1 = ebuf; *s1++ = *s2++; ) |
for (s1 = ebuf; (*s1++ = *s2++); ) |
; |
; |
s2 = --s1; |
s2 = --s1; |
if (s3 != NULL) { |
if (s3 != NULL) { |
s2++; |
s2++; |
while (*s1++ = *s3++) |
while ((*s1++ = *s3++)) |
; |
; |
} |
} |
return(s2); |
return(s2); |
|
|
tv[0].tv_usec = tv[1].tv_usec = (time_t) 0; |
tv[0].tv_usec = tv[1].tv_usec = (time_t) 0; |
return(utimes(file, tv)); |
return(utimes(file, tv)); |
} else /* Set to current time */ |
} else /* Set to current time */ |
return(utimes(file, (struct timeval *) NULL)); |
return(utimes(file, NULL)); |
|
|
#endif /* SETFTIME_UTIMES */ |
#endif /* SETFTIME_UTIMES */ |
|
|
|
|
utbuf.modtime = mtime; |
utbuf.modtime = mtime; |
return(utime(file, &utbuf)); |
return(utime(file, &utbuf)); |
} else /* Set to current time */ |
} else /* Set to current time */ |
return(utime(file, (struct utimbuf *)NULL)); |
return(utime(file, NULL)); |
#endif /* SETFTIME_UTIME */ |
#endif /* SETFTIME_UTIME */ |
|
|
#if !defined(SETFTIME_TYPE) |
#if !defined(SETFTIME_TYPE) |
|
|
{ |
{ |
register char *cp; |
register char *cp; |
|
|
if (cp = strrchr(path, '/')) |
if ((cp = strrchr(path, '/'))) |
return(cp+1); |
return(cp+1); |
else |
else |
return(path); |
return(path); |
|
|
|
|
for (; ;) { |
for (; ;) { |
if (!path) |
if (!path) |
return((char *) NULL); |
return(NULL); |
file = path; |
file = path; |
cp = strchr(path, ':'); |
cp = strchr(path, ':'); |
if (cp) { |
if (cp) { |
|
|
/* |
/* |
* Set line buffering. |
* Set line buffering. |
*/ |
*/ |
extern int |
extern void |
mysetlinebuf(fp) |
mysetlinebuf(fp) |
FILE *fp; |
FILE *fp; |
{ |
{ |
#if SETBUF_TYPE == SETBUF_SETLINEBUF |
#if SETBUF_TYPE == SETBUF_SETLINEBUF |
return(setlinebuf(fp)); |
setlinebuf(fp); |
#endif /* SETBUF_SETLINEBUF */ |
#endif /* SETBUF_SETLINEBUF */ |
#if SETBUF_TYPE == SETBUF_SETVBUF |
#if SETBUF_TYPE == SETBUF_SETVBUF |
return(setvbuf(stdout, NULL, _IOLBF, BUFSIZ)); |
setvbuf(stdout, NULL, _IOLBF, BUFSIZ); |
#endif /* SETBUF_SETVBUF */ |
#endif /* SETBUF_SETVBUF */ |
#if !defined(SETBUF_TYPE) |
#if !defined(SETBUF_TYPE) |
No SETBUF_TYPE is defined! |
No SETBUF_TYPE is defined! |