1: #ifndef lint
   2: static char sccsid[] = "@(#)expfile.c	5.5 (Berkeley) 6/19/85";
   3: #endif
   4: 
   5: #include "uucp.h"
   6: #include <sys/stat.h>
   7: 
   8: /*LINTLIBRARY*/
   9: 
  10: /*
  11:  *	expand file name
  12:  *
  13:  *	return codes: 0 - Ordinary spool area file
  14:  *		      1 - Other normal file
  15:  *		      FAIL - no Wrkdir name available
  16:  */
  17: 
  18: expfile(file)
  19: char *file;
  20: {
  21:     register char *fpart, *p;
  22:     char user[WKDSIZE], *up;
  23:     char full[MAXFULLNAME];
  24:     int uid;
  25: 
  26:     switch(file[0]) {
  27:     case '/':
  28:         return 1;
  29:     case '~':
  30:         for (fpart = file + 1, up = user; *fpart != '\0'
  31:             && *fpart != '/'; fpart++)
  32:                 *up++ = *fpart;
  33:         *up = '\0';
  34:         if (!*user || gninfo(user, &uid, full) != 0) {
  35:             strcpy(full, PUBDIR);
  36:         }
  37: 
  38:         strcat(full, fpart);
  39:         strcpy(file, full);
  40:         return 1;
  41:     default:
  42:         p = index(file, '/');
  43:         strcpy(full, Wrkdir);
  44:         strcat(full, "/");
  45:         strcat(full, file);
  46:         strcpy(file, full);
  47:         if (Wrkdir[0] == '\0')
  48:             return FAIL;
  49:         else if (p != NULL)
  50:             return 1;
  51:         return 0;
  52:     }
  53: }
  54: 
  55: 
  56: /*
  57:  *	check if directory name
  58:  *
  59:  *	return codes:  0 - not directory  |  1 - is directory
  60:  */
  61: 
  62: isdir(name)
  63: char *name;
  64: {
  65:     register int ret;
  66:     struct stat s;
  67: 
  68:     ret = stat(subfile(name), &s);
  69:     if (ret < 0)
  70:         return 0;
  71:     if ((s.st_mode & S_IFMT) == S_IFDIR)
  72:         return 1;
  73:     return 0;
  74: }
  75: 
  76: 
  77: /*
  78:  *	make all necessary directories
  79:  *
  80:  *	return SUCCESS  |  FAIL
  81:  */
  82: 
  83: mkdirs(name)
  84: char *name;
  85: {
  86:     int ret, mask;
  87:     char dir[MAXFULLNAME];
  88:     register char *p;
  89: 
  90:     for (p = dir + 1;; p++) {
  91:         strcpy(dir, name);
  92:         if ((p = index(p, '/')) == NULL)
  93:             return SUCCESS;
  94:         *p = '\0';
  95:         if (isdir(dir))
  96:             continue;
  97: 
  98:         DEBUG(4, "mkdir - %s\n", dir);
  99:         mask = umask(0);
 100:         ret = mkdir(dir, 0777);
 101:         umask(mask);
 102:         if (ret != 0)
 103:             return FAIL;
 104:     }
 105:     /* NOTREACHED */
 106: }
 107: 
 108: /*
 109:  *	expfile and check return
 110:  *		print error if it failed.
 111:  *
 112:  *	return code - SUCCESS - ok; FAIL if expfile failed
 113:  */
 114: 
 115: ckexpf(file)
 116: register char *file;
 117: {
 118: 
 119:     if (expfile(file) != FAIL)
 120:         return SUCCESS;
 121: 
 122:     /*  could not expand file name */
 123:     /* the gwd routine failed */
 124: 
 125:     logent("CAN'T EXPAND FILENAME - PWD FAILED", file+1);
 126:     return FAIL;
 127: }

Defined functions

ckexpf defined in line 115; used 13 times
expfile defined in line 18; used 12 times
isdir defined in line 62; used 4 times
mkdirs defined in line 83; used 2 times

Defined variables

sccsid defined in line 2; never used
Last modified: 1987-02-17
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2500
Valid CSS Valid XHTML 1.0 Strict