Annotation of coherent/g/usr/lib/uucp/tay104/unix/picksb.c, revision 1.1

1.1     ! root        1: /* picksb.c
        !             2:    System dependent routines for uupick.
        !             3: 
        !             4:    Copyright (C) 1992 Ian Lance Taylor
        !             5: 
        !             6:    This file is part of the Taylor UUCP package.
        !             7: 
        !             8:    This program is free software; you can redistribute it and/or
        !             9:    modify it under the terms of the GNU General Public License as
        !            10:    published by the Free Software Foundation; either version 2 of the
        !            11:    License, or (at your option) any later version.
        !            12: 
        !            13:    This program is distributed in the hope that it will be useful, but
        !            14:    WITHOUT ANY WARRANTY; without even the implied warranty of
        !            15:    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
        !            16:    General Public License for more details.
        !            17: 
        !            18:    You should have received a copy of the GNU General Public License
        !            19:    along with this program; if not, write to the Free Software
        !            20:    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
        !            21: 
        !            22:    The author of the program may be contacted at [email protected] or
        !            23:    c/o Infinity Development Systems, P.O. Box 520, Waltham, MA 02254.
        !            24:    */
        !            25: 
        !            26: #include "uucp.h"
        !            27: 
        !            28: #if USE_RCS_ID
        !            29: const char picksb_rcsid[] = "$Id: picksb.c,v 1.1 93/07/30 08:02:42 bin Exp Locker: bin $";
        !            30: #endif
        !            31: 
        !            32: #include "uudefs.h"
        !            33: #include "system.h"
        !            34: #include "sysdep.h"
        !            35: 
        !            36: #include <errno.h>
        !            37: #include <pwd.h>
        !            38: 
        !            39: #if HAVE_OPENDIR
        !            40: #if HAVE_DIRENT_H
        !            41: #include <dirent.h>
        !            42: #else /* ! HAVE_DIRENT_H */
        !            43: #include <sys/dir.h>
        !            44: #define dirent direct
        !            45: #endif /* ! HAVE_DIRENT_H */
        !            46: #endif /* HAVE_OPENDIR */
        !            47: 
        !            48: #if GETPWUID_DECLARATION_OK
        !            49: #ifndef getpwuid
        !            50: extern struct passwd *getpwuid ();
        !            51: #endif
        !            52: #endif
        !            53: 
        !            54: /* Local variables.  */
        !            55: 
        !            56: /* Directory of ~/receive/USER.  */
        !            57: static DIR *qStopdir;
        !            58: 
        !            59: /* Name of ~/receive/USER.  */
        !            60: static char *zStopdir;
        !            61: 
        !            62: /* Directory of ~/receive/USER/SYSTEM.  */
        !            63: static DIR *qSsysdir;
        !            64: 
        !            65: /* Name of system.  */
        !            66: static char *zSsysdir;
        !            67: 
        !            68: /* Prepare to get a list of all the file to uupick for this user.  */
        !            69: 
        !            70: /*ARGSUSED*/
        !            71: boolean
        !            72: fsysdep_uupick_init (zsystem, zpubdir)
        !            73:      const char *zsystem;
        !            74:      const char *zpubdir;
        !            75: {
        !            76:   const char *zuser;
        !            77: 
        !            78:   zuser = zsysdep_login_name ();
        !            79: 
        !            80:   zStopdir = (char *) xmalloc (strlen (zpubdir)
        !            81:                               + sizeof "/receive/"
        !            82:                               + strlen (zuser));
        !            83:   sprintf (zStopdir, "%s/receive/%s", zpubdir, zuser);
        !            84: 
        !            85:   qStopdir = opendir (zStopdir);
        !            86:   if (qStopdir == NULL && errno != ENOENT)
        !            87:     {
        !            88:       ulog (LOG_ERROR, "opendir (%s): %s", zStopdir,
        !            89:            strerror (errno));
        !            90:       return FALSE;
        !            91:     }
        !            92: 
        !            93:   qSsysdir = NULL;
        !            94: 
        !            95:   return TRUE;
        !            96: }
        !            97: 
        !            98: /* Return the next file from the uupick directories.  */
        !            99: 
        !           100: /*ARGSUSED*/
        !           101: char *
        !           102: zsysdep_uupick (zsysarg, zpubdir, pzfrom, pzfull)
        !           103:      const char *zsysarg;
        !           104:      const char *zpubdir;
        !           105:      char **pzfrom;
        !           106:      char **pzfull;
        !           107: {
        !           108:   struct dirent *qentry;
        !           109: 
        !           110:   while (TRUE)
        !           111:     {
        !           112:       while (qSsysdir == NULL)
        !           113:        {
        !           114:          const char *zsystem;
        !           115:          char *zdir;
        !           116: 
        !           117:          if (qStopdir == NULL)
        !           118:            return NULL;
        !           119: 
        !           120:          if (zsysarg != NULL)
        !           121:            {
        !           122:              closedir (qStopdir);
        !           123:              qStopdir = NULL;
        !           124:              zsystem = zsysarg;
        !           125:            }
        !           126:          else
        !           127:            {
        !           128:              do
        !           129:                {
        !           130:                  qentry = readdir (qStopdir);
        !           131:                  if (qentry == NULL)
        !           132:                    {
        !           133:                      closedir (qStopdir);
        !           134:                      qStopdir = NULL;
        !           135:                      return NULL;
        !           136:                    }
        !           137:                }
        !           138:              while (strcmp (qentry->d_name, ".") == 0
        !           139:                     || strcmp (qentry->d_name, "..") == 0);
        !           140: 
        !           141:              zsystem = qentry->d_name;
        !           142:            }
        !           143: 
        !           144:          zdir = zbufalc (strlen (zStopdir) + strlen (zsystem) + sizeof "/");
        !           145:          sprintf (zdir, "%s/%s", zStopdir, zsystem);
        !           146: 
        !           147:          qSsysdir = opendir (zdir);
        !           148:          if (qSsysdir == NULL)
        !           149:            {
        !           150:              if (errno != ENOENT && errno != ENOTDIR)
        !           151:                ulog (LOG_ERROR, "opendir (%s): %s", zdir, strerror (errno));
        !           152:            }
        !           153:          else
        !           154:            {
        !           155:              ubuffree (zSsysdir);
        !           156:              zSsysdir = zbufcpy (zsystem);
        !           157:            }
        !           158: 
        !           159:          ubuffree (zdir);
        !           160:        }
        !           161: 
        !           162:       qentry = readdir (qSsysdir);
        !           163:       if (qentry == NULL)
        !           164:        {
        !           165:          closedir (qSsysdir);
        !           166:          qSsysdir = NULL;
        !           167:          continue;
        !           168:        }
        !           169: 
        !           170:       if (strcmp (qentry->d_name, ".") == 0
        !           171:          || strcmp (qentry->d_name, "..") == 0)
        !           172:        continue;
        !           173: 
        !           174:       *pzfrom = zbufcpy (zSsysdir);
        !           175:       *pzfull = zsappend3 (zStopdir, zSsysdir, qentry->d_name);
        !           176:       return zbufcpy (qentry->d_name);
        !           177:     }
        !           178: }
        !           179: 
        !           180: /*ARGSUSED*/
        !           181: boolean
        !           182: fsysdep_uupick_free (zsystem, zpubdir)
        !           183:      const char *zsystem;
        !           184:      const char *zpubdir;
        !           185: {
        !           186:   xfree ((pointer) zStopdir);
        !           187:   if (qStopdir != NULL)
        !           188:     {
        !           189:       closedir (qStopdir);
        !           190:       qStopdir = NULL;
        !           191:     }
        !           192:   ubuffree (zSsysdir);
        !           193:   zSsysdir = NULL;
        !           194:   if (qSsysdir != NULL)
        !           195:     {
        !           196:       closedir (qSsysdir);
        !           197:       qSsysdir = NULL;
        !           198:     }
        !           199: 
        !           200:   return TRUE;
        !           201: }
        !           202: 
        !           203: /* Expand a local file name for uupick.  */
        !           204: 
        !           205: char *
        !           206: zsysdep_uupick_local_file (zfile)
        !           207:      const char *zfile;
        !           208: {
        !           209:   struct passwd *q;
        !           210: 
        !           211:   /* If this does not start with a simple ~, pass it to
        !           212:      zsysdep_local_file_cwd; as it happens, zsysdep_local_file_cwd
        !           213:      only uses the zpubdir argument if the file starts with a simple
        !           214:      ~, so it doesn't really matter what we pass for zpubdir.  */
        !           215:   if (zfile[0] != '~'
        !           216:       || (zfile[1] != '/' && zfile[1] != '\0'))
        !           217:     return zsysdep_local_file_cwd (zfile, (const char *) NULL);
        !           218:   
        !           219:   q = getpwuid (getuid ());
        !           220:   if (q == NULL)
        !           221:     {
        !           222:       ulog (LOG_ERROR, "Can't get home directory");
        !           223:       return NULL;
        !           224:     }
        !           225: 
        !           226:   if (zfile[1] == '\0')
        !           227:     return zbufcpy (q->pw_dir);
        !           228: 
        !           229:   return zsysdep_in_dir (q->pw_dir, zfile + 2);
        !           230: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.