#include #include #include #include #include #include #include #include #ifdef SYSV #include #include #endif #include char **Exceptions; int *NeedsPortableNewlines; int ExceptionsAlloced = 0, ExceptionsUsed = 0; int lc2strncmp(); int lc2strcmp(); int ExceptionalNewline(contenttype, needsportable) char *contenttype; int needsportable; { char *s; if (ExceptionsAlloced == 0) { ExceptionsAlloced = 25; Exceptions = (char **) malloc(ExceptionsAlloced * sizeof(char *)); NeedsPortableNewlines = (int *) malloc(ExceptionsAlloced * sizeof(int)); if (!Exceptions || !NeedsPortableNewlines) return(-1); } if (ExceptionsUsed >= ExceptionsAlloced) { ExceptionsAlloced += 25; Exceptions = (char **) realloc(Exceptions, ExceptionsAlloced * sizeof(char *)); NeedsPortableNewlines = (int *) realloc(NeedsPortableNewlines, ExceptionsAlloced * sizeof(int)); if (!Exceptions || !NeedsPortableNewlines) return(-1); } s = malloc(1+strlen(contenttype)); if (!s) return(-1); strcpy(s, contenttype); Exceptions[ExceptionsUsed] = s; for (; *s; ++s) { if (isupper((unsigned char) *s)) *s = tolower((unsigned char) *s); } NeedsPortableNewlines[ExceptionsUsed] = needsportable; ++ExceptionsUsed; return(0); } int DoesNeedPortableNewlines(ctype) char *ctype; { int i; /* First, handle the customization/override case */ for (i=0; i 0) { if (*s1 != *s2 && (tolower(*s1) != *s2)) return(-1); ++s1; ++s2; --len; } if (len <= 0) return(0); return((*s1 == *s2) ? 0 : -1); } int lc2strcmp(s1, s2) char *s1, *s2; { if (!s1 || !s2) return (-1); while (*s1 && *s2) { if (*s1 != *s2 && (tolower(*s1) != *s2)) return(-1); ++s1; ++s2; } return((*s1 == *s2) ? 0 : -1); } char *getmyname() { static int initialized = 0; #ifdef SYSV static struct utsname u; static char *hostname = u.nodename; #else static char hostname[60]; #endif if (!initialized) { #ifdef AMIGA strcpy(hostname, myAddress); #else #ifdef SYSV if (uname(&u) == -1) { hostname = "UNKNOWN.SITE.NAME"; } #else #ifdef MSDOS strcpy(hostname, "UNKNOWN.SITE.NAME"); #else gethostname(hostname, sizeof(hostname)); #endif /* MSDOS */ #endif /* SYSV */ #endif /* AMIGA */ initialized = 1; } return(hostname); } /* This fopen wrapper function is designed to avoid /tmp-file race * conditions where a temporary filename is created and somebody * throws a link in your way before the fopen(...,"w"). This * would only happen if another user on the system were actively * trying to trick you into destroying files. * Sorry, but "a" mode is not really handled any safer than fopen, * since I really have no criterium for deciding what files are * OK to write to. */ FILE *Fopen(Fopen_path,Fopen_mode) char *Fopen_path; char *Fopen_mode; { #ifdef MSDOS return(fopen(Fopen_path,Fopen_mode)); #else int Fopen_fd; struct stat Fopen_sb; int Fopen_appendmode = 0; int Fopen_readmode = 0; int Fopen_openflags = 0; int Fopen_r; if ( strchr(Fopen_mode,'r') != (char *)0 ) return(fopen(Fopen_path,Fopen_mode)); if ( strchr(Fopen_mode,'a') != (char *)0 ) Fopen_appendmode = 1; if ( strchr(Fopen_mode,'+') != (char *)0 ) Fopen_readmode = 1; if ( ( Fopen_appendmode && (strchr(Fopen_mode,'w') != (char *)0) ) || ( (! Fopen_appendmode) && (strchr(Fopen_mode,'w') == (char *)0) ) ) { errno = EINVAL ; return( (FILE *)0 ); } if ( Fopen_appendmode ) { /* If "a" and file exists, pass it to the real fopen() */ Fopen_r = stat(Fopen_path,&Fopen_sb) ; if ( (Fopen_r != -1) || (errno != ENOENT) ) return( fopen(Fopen_path,Fopen_mode) ); } if ( Fopen_readmode ) Fopen_openflags = O_RDWR|O_CREAT|O_EXCL ; else Fopen_openflags = O_WRONLY|O_CREAT|O_EXCL ; if ( Fopen_appendmode ) Fopen_openflags |= O_APPEND ; remove( Fopen_path ); /* 0666? We'd better hope their umask is safe... */ Fopen_fd = open(Fopen_path,Fopen_openflags,0666); if ( Fopen_fd > -1 ) return( fdopen(Fopen_fd,Fopen_mode) ); return( (FILE *)0 ); #endif }