home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume14 / 3bconnect / sub.c < prev    next >
C/C++ Source or Header  |  1988-05-08  |  2KB  |  88 lines

  1. /*
  2.  * sub.c: general subroutines for "rcp"
  3.  * remote(s): check if "s" refers to a local(0) or remote(1) file.
  4.  * sysname(s): return systemname assosciated with s. "localnode" returned
  5.  *         if there is no specific "sys!" prefix.
  6.  * filename(s): return filname part - strip first system prefix, if there is one
  7.  * 
  8.  * fmode(s): return value of file mode.
  9.  *
  10.  * lastpart(f): return last entry of path 'f'
  11.  */
  12.  
  13. #define rindex strrchr
  14. #define index strchr
  15.  
  16. char *filename(), *sysname(), *lastpart(), *malloc(), 
  17.     *strrchr(), *strchr();
  18. extern char *sys_errlist[];
  19. #include "errno.h"
  20. #include <stdio.h>
  21. #include <time.h>
  22. #include <sys/types.h>
  23. #include <sys/stat.h>
  24.  
  25. #include "ni.h"
  26. long time();
  27. char *asctime();
  28. struct tm *localtime();
  29.  
  30. remote(s)
  31. char *s;
  32. {
  33.     if(filename(s) == s) return(0);
  34.     else return(1);
  35. }
  36. /*
  37.  * sysname(f): get system name part of file name.
  38.  * if no system present, return localnode
  39.  */
  40. char *sysname(f)
  41. char *f;
  42. {
  43.     register char *p, *sys;
  44.     register int length;
  45.     if((p = filename(f)) == f) return(localnode);
  46.     else {
  47.         sys = malloc(length = p - f);
  48.         strncpy(sys, f, length - 1);
  49.         sys[length - 1] = 0;
  50.         return(sys);
  51.     }
  52. }
  53. /*
  54.  * filename(f): return file name part of f
  55.  * Strips the first (and only the first) system, if there is one.
  56.  * [8] Also allow ':' as system flag.
  57.  */
  58. char *filename(f)
  59. register char *f;
  60. {
  61.     register char *s;
  62.     if((s = index(f, '!')) || (s = index(f, ':'))) return(++s);
  63.     else return(f);
  64. }
  65. bang(c)
  66. char c;
  67. {
  68.     if((c == '!') || (c == ':')) return(1);
  69.     else return(0);
  70. }
  71.  
  72. fmode(f)
  73. char *f;
  74. {
  75.     struct stat s;
  76.     if(stat(f, &s) == -1) return(0664);
  77.     return(s.st_mode);
  78. }
  79.  
  80. char *lastpart(f)
  81. char *f;
  82. {
  83.     char *l;
  84.     if(l = rindex(f, '/')) return(++l);
  85.     else return(f);
  86. }
  87.     
  88.