home *** CD-ROM | disk | FTP | other *** search
/ Serving the Web / ServingTheWeb1995.disc1of1.iso / linux / slacksrce / d / libc / libc-4.6 / libc-4 / libc-linux / sbin / sln.c < prev   
Encoding:
C/C++ Source or Header  |  1993-05-07  |  1.6 KB  |  73 lines

  1. /* `sln' program to create links between files.
  2.    Copyright (C) 1986, 1989, 1990, 1991, 1993 Free Software Foundation, Inc.
  3.  
  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 2, or (at your option)
  7.    any later version.
  8.  
  9.    This program is distributed in the hope that it will be useful,
  10.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.    GNU General Public License for more details.
  13.  
  14.    You should have received a copy of the GNU General Public License
  15.    along with this program; if not, write to the Free Software
  16.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  17.  
  18. /* Written by Mike Parker and David MacKenzie. */
  19.  
  20. #include <sys/types.h>
  21. #include <sys/stat.h>
  22. #include <unistd.h>
  23. #include <errno.h>
  24.  
  25. #if !defined(S_ISDIR) && defined(S_IFDIR)
  26. #define    S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
  27. #endif
  28.  
  29. int
  30. main (argc, argv)
  31.      int argc;
  32.      char **argv;
  33. {
  34.   struct stat stats;
  35.  
  36.   if (argc != 3) return 1;
  37.  
  38.   /* Destination must not be a directory. */
  39. #if 0
  40.   if (stat (argv [2], &stats) == 0 && S_ISDIR (stats.st_mode))
  41.     {
  42.       return 1;
  43.     }
  44. #endif
  45.  
  46.   if (lstat (argv [2], &stats) == 0)
  47.     {
  48.       if (S_ISDIR (stats.st_mode))
  49.     {
  50.       return 1;
  51.     }
  52.       else if (unlink (argv [2]) && errno != ENOENT)
  53.     {
  54.       return 1;
  55.     }
  56.     }
  57.   else if (errno != ENOENT)
  58.     {
  59.       return 1;
  60.     }
  61.        
  62. #ifdef S_ISLNK
  63.   if (symlink (argv [1], argv [2]) == 0)
  64. #else
  65.   if (link (argv [1], argv [2]) == 0)
  66. #endif
  67.     {
  68.       return 0;
  69.     }
  70.  
  71.   return 1;
  72. }
  73.