home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / info-service / gopher / Unix / gopher+1.2b4 / object / compatible.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-04-15  |  8.5 KB  |  308 lines

  1. /********************************************************************
  2.  * lindner
  3.  * 3.4
  4.  * 1993/04/15 21:36:30
  5.  * /home/mudhoney/GopherSrc/CVS/gopher+/object/compatible.c,v
  6.  * Exp
  7.  *
  8.  * Paul Lindner, University of Minnesota CIS.
  9.  *
  10.  * Copyright 1991, 1992 by the Regents of the University of Minnesota
  11.  * see the file "Copyright" in the distribution for conditions of use.
  12.  *********************************************************************
  13.  * MODULE: compatible.c
  14.  * Compatibility routines
  15.  *********************************************************************
  16.  * Revision History:
  17.  * compatible.c,v
  18.  * Revision 3.4  1993/04/15  21:36:30  lindner
  19.  * Emulation of geteuid calls for HPs
  20.  *
  21.  * Revision 3.3  1993/03/18  22:27:46  lindner
  22.  * better portable tempnam()
  23.  *
  24.  * Revision 3.2  1993/02/19  21:33:27  lindner
  25.  * Gopher1.2b2 release
  26.  *
  27.  * Revision 3.1.1.1  1993/02/11  18:03:05  lindner
  28.  * Gopher+1.2beta release
  29.  *
  30.  * Revision 1.4  1993/01/17  03:46:12  lindner
  31.  * Fixed tempnam for VMS
  32.  *
  33.  * Revision 1.3  1993/01/08  23:13:55  lindner
  34.  * Added more VMS mods from jqj
  35.  *
  36.  *
  37.  *********************************************************************/
  38.  
  39.  
  40. /*
  41.  * Some functions that aren't implemented on every machine on the net
  42.  *
  43.  * definitions should be in the form "NO_FNNAME"
  44.  * compatible.h looks at preprocessor symbols and automatically defines
  45.  * many of the NO_FNNAME options
  46.  *
  47.  */
  48.  
  49. #include <string.h>
  50. #include <stdio.h>
  51. #include "Malloc.h"  /*** For NULL ***/
  52. #include "compatible.h"
  53.  
  54. /*** For machines that don't have strstr ***/
  55.  
  56. #if defined(NOSTRSTR)
  57.  
  58. char *
  59. strstr(host_name, cp)
  60.   char *host_name;
  61.   char *cp;
  62. {
  63.      int i, j;
  64.  
  65.      for (i = 0; i < strlen(host_name); i++) {
  66.           j = strncmp(host_name+i, cp, strlen(cp));
  67.           if (j == 0)
  68.                return(host_name+i);
  69.      }
  70.      return(NULL);
  71. }
  72. #endif
  73.  
  74. #if defined(sequent)
  75.  
  76. #include <varargs.h>
  77. vsprintf(va_alist)
  78.   va_dcl
  79. {
  80.         ;
  81. }
  82.  
  83. vfprintf(va_alist)
  84.   va_dcl
  85. {
  86.         ;
  87. }
  88.  
  89.  
  90. #endif
  91.  
  92. #if defined(NO_TEMPNAM)
  93. /* A tip of the hat to the developers of elm 2.4pl17, from whence 
  94.    the non-VMS portion of this routine comes.  
  95. */
  96. /* and a tempnam for temporary files */
  97. static int cnt = 0;
  98.  
  99. char *tempnam(dir, pfx)
  100.   char *dir;
  101.   char *pfx;
  102. {
  103. #ifndef VMS
  104.     char space[512];
  105.     char *newspace;
  106.  
  107.     if (dir == NULL) {
  108.         dir = "/usr/tmp";
  109.     } else if (*dir == '\0') {
  110.         dir = "/usr/tmp";
  111.     }
  112.     
  113.     if (pfx == NULL) {
  114.         pfx = "";
  115.     }
  116.  
  117.     sprintf(space, "%s/%s%d.%d", dir, pfx, getpid(), cnt);
  118.     cnt++;
  119.     
  120.     newspace = (char *)malloc(strlen(space) + 1);
  121.     if (newspace != NULL) {
  122.         strcpy(newspace, space);
  123.     }
  124.     return newspace;
  125. #else
  126.     char *tmpname;
  127.     register int len;
  128.         char tmpfilename[L_tmpnam];
  129.  
  130.         (void) tmpnam(tmpfilename);
  131.     len = strlen(tmpfilename)+13;
  132.     tmpname = (char *) malloc(sizeof(char)*len+1);
  133.         sprintf(tmpname,"sys$scratch:%s.",tmpfilename);
  134.         return(tmpname);
  135. #endif
  136. }
  137. #endif
  138.  
  139. #if defined(NO_STRDUP)
  140. char *strdup(str)
  141.   char *str;
  142. {
  143.         int len;
  144.         char *temp;
  145.  
  146.         if (str == NULL) return(NULL);
  147.         len = strlen(str);
  148.  
  149.         temp = (char *) malloc(sizeof(char) * len + 1);
  150.  
  151.         strcpy(temp, str);
  152.         return(temp);
  153. }
  154. #endif
  155.  
  156. #if defined(NO_TZSET)
  157. void
  158. tzset()
  159. {
  160.      ;
  161. }
  162. #endif
  163.  
  164. #if defined(NO_STRCASECMP)
  165. /*
  166.  * Copyright (c) 1987 Regents of the University of California.
  167.  * All rights reserved.
  168.  *
  169.  * Redistribution and use in source and binary forms, with or without
  170.  * modification, are permitted provided that the following conditions
  171.  * are met:
  172.  * 1. Redistributions of source code must retain the above copyright
  173.  *    notice, this list of conditions and the following disclaimer.
  174.  * 2. Redistributions in binary form must reproduce the above copyright
  175.  *    notice, this list of conditions and the following disclaimer in the
  176.  *    documentation and/or other materials provided with the distribution.
  177.  * 3. All advertising materials mentioning features or use of this software
  178.  *    must display the following acknowledgement:
  179.  *    This product includes software developed by the University of
  180.  *    California, Berkeley and its contributors.
  181.  * 4. Neither the name of the University nor the names of its contributors
  182.  *    may be used to endorse or promote products derived from this software
  183.  *    without specific prior written permission.
  184.  *
  185.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  186.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  187.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  188.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  189.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  190.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  191.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  192.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  193.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  194.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  195.  * SUCH DAMAGE.
  196.  *
  197.  * Modified for use on VMS by Earl Fogel, University of Saskatchewan
  198.  * Computing Services, January 1992
  199.  */
  200.  
  201. typedef unsigned char u_char;
  202.  
  203. /*
  204.  * This array is designed for mapping upper and lower case letter
  205.  * together for a case independent comparison.  The mappings are
  206.  * based upon ascii character sequences.
  207.  */
  208. static const u_char charmap[] = {
  209.     '\000', '\001', '\002', '\003', '\004', '\005', '\006', '\007',
  210.     '\010', '\011', '\012', '\013', '\014', '\015', '\016', '\017',
  211.     '\020', '\021', '\022', '\023', '\024', '\025', '\026', '\027',
  212.     '\030', '\031', '\032', '\033', '\034', '\035', '\036', '\037',
  213.     '\040', '\041', '\042', '\043', '\044', '\045', '\046', '\047',
  214.     '\050', '\051', '\052', '\053', '\054', '\055', '\056', '\057',
  215.     '\060', '\061', '\062', '\063', '\064', '\065', '\066', '\067',
  216.     '\070', '\071', '\072', '\073', '\074', '\075', '\076', '\077',
  217.     '\100', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
  218.     '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
  219.     '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
  220.     '\170', '\171', '\172', '\133', '\134', '\135', '\136', '\137',
  221.     '\140', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
  222.     '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
  223.     '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
  224.     '\170', '\171', '\172', '\173', '\174', '\175', '\176', '\177',
  225.     '\200', '\201', '\202', '\203', '\204', '\205', '\206', '\207',
  226.     '\210', '\211', '\212', '\213', '\214', '\215', '\216', '\217',
  227.     '\220', '\221', '\222', '\223', '\224', '\225', '\226', '\227',
  228.     '\230', '\231', '\232', '\233', '\234', '\235', '\236', '\237',
  229.     '\240', '\241', '\242', '\243', '\244', '\245', '\246', '\247',
  230.     '\250', '\251', '\252', '\253', '\254', '\255', '\256', '\257',
  231.     '\260', '\261', '\262', '\263', '\264', '\265', '\266', '\267',
  232.     '\270', '\271', '\272', '\273', '\274', '\275', '\276', '\277',
  233.     '\300', '\301', '\302', '\303', '\304', '\305', '\306', '\307',
  234.     '\310', '\311', '\312', '\313', '\314', '\315', '\316', '\317',
  235.     '\320', '\321', '\322', '\323', '\324', '\325', '\326', '\327',
  236.     '\330', '\331', '\332', '\333', '\334', '\335', '\336', '\337',
  237.     '\340', '\341', '\342', '\343', '\344', '\345', '\346', '\347',
  238.     '\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357',
  239.     '\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367',
  240.     '\370', '\371', '\372', '\373', '\374', '\375', '\376', '\377',
  241. };
  242.  
  243. int
  244. strcasecmp(s1, s2)
  245.     const char *s1, *s2;
  246. {
  247.     register const u_char *cm = charmap,
  248.             *us1 = (const u_char *)s1,
  249.             *us2 = (const u_char *)s2;
  250.  
  251.     while (cm[*us1] == cm[*us2++])
  252.         if (*us1++ == '\0')
  253.             return (0);
  254.     return (cm[*us1] - cm[*--us2]);
  255. }
  256.  
  257. int
  258. strncasecmp(s1, s2, n)
  259.     const char *s1, *s2;
  260.     register size_t n;
  261. {
  262.     if (n != 0) {
  263.         register const u_char *cm = charmap,
  264.                 *us1 = (const u_char *)s1,
  265.                 *us2 = (const u_char *)s2;
  266.  
  267.         do {
  268.             if (cm[*us1] != cm[*us2++])
  269.                 return (cm[*us1] - cm[*--us2]);
  270.             if (*us1++ == '\0')
  271.                 break;
  272.         } while (--n != 0);
  273.     }
  274.     return (0);
  275. }
  276.  
  277. #endif
  278.  
  279. #if defined(VMS)
  280. /* In all versions of VMS, fopen() and open() are needlessly inefficient.
  281.  * Define jacket routines to do file opens with more sensible parameters
  282.  * than the VAXCRTL default.
  283.  * [Should we really be doing this for EVERY fopen() and open()?]
  284.  */
  285. #ifdef fopen
  286. #undef fopen
  287. #endif
  288. #ifdef open
  289. #undef open
  290. #endif
  291.  
  292. FILE *fopen_VMSopt ( name, mode )
  293.     char *name, *mode;
  294. {
  295.     return fopen ( name, mode, "mbc=32" );
  296. }
  297.  
  298. int open_VMSopt ( name, flags, mode )
  299.     char *name;
  300.     int flags;
  301.     unsigned int mode;
  302. {
  303.     return  open ( name, flags, mode, "mbc=32");
  304. }
  305. #endif
  306.  
  307.  
  308.