home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OS9000 / APPS / rcs.lzh / rcs1 / osk.c < prev    next >
Text File  |  1996-04-20  |  2KB  |  135 lines

  1. /*
  2. **    $Id: osk.c_v 1.3 96/04/07 00:07:30 hiro Exp $
  3. */
  4. /*
  5.  *    $Log:    osk.c_v $
  6.  * Revision 1.3  96/04/07  00:07:30  hiro
  7.  * Ported to OS-9000.
  8.  * 
  9.  * Revision 1.2  95/10/23  00:45:38  hiro
  10.  * Reverted rename for _UCC because the current rename library is not
  11.  * compatible with NFS.
  12.  * 
  13.  * Revision 1.1  93/04/02  01:26:33  hiro
  14.  * Initial revision
  15.  * 
  16.  * Revision 1.1  90/07/23  10:26:24  momo
  17.  * Initial revision
  18.  * 
  19. */
  20. #include <stdio.h>
  21. #include <sgstat.h>
  22. #include <sg_codes.h>
  23. #include <modes.h>
  24.  
  25. #ifndef DT_SCF
  26. #include <io.h>
  27. #endif
  28.  
  29. #if defined(_UCC) || defined(_OS9000)
  30. #define environ _environ
  31. #endif
  32.  
  33. #define STDIN         0
  34. #define STDOUT        1
  35. #define STDERR        2
  36. #define ERR            (-1)
  37. #define TRUE        (-1)
  38. #define FALSE        0
  39. extern char **environ;
  40. extern int    errno;
  41.  
  42. #ifndef _UCC
  43. void perror(buf)
  44. char *buf;
  45. {
  46.     fputs(buf,stderr);
  47.     fflush(stderr);
  48. }
  49.  
  50. int remove(file)
  51. {
  52.     return unlink(file);
  53. }
  54. #endif
  55.  
  56. #ifdef _UCC
  57. int _rename(from,to)
  58. #else
  59. int rename(from,to)
  60. #endif
  61. char *from,*to;
  62. {
  63.     register char *p , *pp;
  64.     char *argv[4];
  65.     int pid , stat , os9fork();
  66.  
  67.     if (access(to , 0) == 0)
  68.     {
  69.         if (unlink(to) == -1)
  70.         {
  71.             if (chmod(to, S_IREAD|S_IWRITE) == -1) return -1;
  72.             if (unlink(to) == -1) return -1;
  73.         }
  74.     }
  75.     argv[0]="rename";
  76.     argv[1]=from;
  77.     for ( p=pp=to ; *p; p++ ) {
  78.         if ( *p=='/' ) pp=p+1;
  79.     }
  80.  
  81.     argv[2] = pp;
  82.     argv[3] = (char *)NULL;
  83.     if ((pid =os9exec(os9fork, argv[0], argv, environ, 0, 128, 3)) == (-1))
  84.         return (-1);
  85.     while (wait(&stat)!=pid) tsleep(10);
  86.     if (stat) { errno=stat; return (-1); }
  87.     return (0);
  88. }
  89.  
  90. /*
  91. **    char pwd( char *buf )
  92. **    return current working directory to buf
  93. */
  94. char *pwd( buf )
  95. char *buf;
  96. {
  97.     int stdinp,stdoutp
  98.         ,pipe,pid,status
  99.         ,os9fork();
  100.     char *argv[2];
  101.  
  102.     if ( (pipe=open("/pipe",3))==ERR ) return NULL;
  103.     stdinp=dup(STDIN); stdoutp=dup(STDOUT);
  104.     close(STDIN); close(STDOUT);
  105.     dup(pipe); dup(pipe);
  106.  
  107.     argv[0]="pd"; argv[1]=0;
  108.     pid=os9exec(os9fork,"pd",argv,environ,0,128,3);
  109.     close(STDIN); close(STDOUT);
  110.     dup(stdinp); dup(stdoutp);
  111.     close(stdinp); close(stdoutp);
  112.     if ( pid!=ERR ) {
  113.         while ( wait(&status)!=pid ) tsleep(10);
  114.         if ( status==0 ) readln(pipe,buf,256);
  115.     }
  116.     close(pipe);
  117.     if ( pid==ERR || status!=0 ) return NULL;
  118.     return buf;
  119. }
  120.  
  121. /*
  122. **    isatty
  123. **    returned value <>0 : SCF Device
  124. **                     0 : Non SCF Device
  125. */
  126. isatty( path )
  127. int path;
  128. {
  129.     struct sgbuf sg;
  130.  
  131.     _gs_opt( path , & sg );
  132.     if ( sg.sg_class==DT_SCF ) return TRUE;
  133.     return FALSE;
  134. }
  135.