home *** CD-ROM | disk | FTP | other *** search
/ OpenStep 4.2J (Developer) / os42jdev.iso / NextDeveloper / Source / GNU / uucp / Uucp.framework / unix.subproj / locfil.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-10-09  |  2.3 KB  |  102 lines

  1. /* locfil.c
  2.    Expand a file name on the local system.
  3.  
  4.    Copyright (C) 1991, 1992, 1993 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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  21.  
  22.    The author of the program may be contacted at ian@airs.com or
  23.    c/o Cygnus Support, 48 Grove Street, Somerville, MA 02144.
  24.    */
  25.  
  26. #include "uucp.h"
  27.  
  28. #include "uudefs.h"
  29. #include "sysdep.h"
  30. #include "system.h"
  31.  
  32. #include <pwd.h>
  33.  
  34. #if GETPWNAM_DECLARATION_OK
  35. #ifndef getpwnam
  36. extern struct passwd *getpwnam ();
  37. #endif
  38. #endif
  39.  
  40. /* Turn a file name into an absolute path, by doing tilde expansion
  41.    and moving any other type of file into the public directory.  */
  42.  
  43. char *
  44. zsysdep_local_file (zfile, zpubdir, pfbadname)
  45.      const char *zfile;
  46.      const char *zpubdir;
  47.      boolean *pfbadname;
  48. {
  49.   const char *zdir;
  50.  
  51.   if (pfbadname != NULL)
  52.     *pfbadname = FALSE;
  53.  
  54.   if (*zfile == '/')
  55.     return zbufcpy (zfile);
  56.  
  57.   if (*zfile != '~')
  58.     zdir = zpubdir;
  59.   else
  60.     {
  61.       if (zfile[1] == '\0')
  62.     return zbufcpy (zpubdir);
  63.  
  64.       if (zfile[1] == '/')
  65.     {
  66.       zdir = zpubdir;
  67.       zfile += 2;
  68.     }
  69.       else
  70.     {
  71.       size_t cuserlen;
  72.       char *zcopy;
  73.       struct passwd *q;
  74.  
  75.       ++zfile;
  76.       cuserlen = strcspn ((char *) zfile, "/");
  77.       zcopy = zbufalc (cuserlen + 1);
  78.       memcpy (zcopy, zfile, cuserlen);
  79.       zcopy[cuserlen] = '\0';
  80.       
  81.       q = getpwnam (zcopy);
  82.       if (q == NULL)
  83.         {
  84.           ulog (LOG_ERROR, "User %s not found", zcopy);
  85.           ubuffree (zcopy);
  86.           if (pfbadname != NULL)
  87.         *pfbadname = TRUE;
  88.           return NULL;
  89.         }
  90.       ubuffree (zcopy);
  91.  
  92.       if (zfile[cuserlen] == '\0')
  93.         return zbufcpy (q->pw_dir);
  94.  
  95.       zdir = q->pw_dir;
  96.       zfile += cuserlen + 1;
  97.     }
  98.     }
  99.  
  100.   return zsysdep_in_dir (zdir, zfile);
  101. }
  102.