home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / APPS / elvis_1.4.tar.Z / elvis_1.4.tar / osk.c < prev    next >
C/C++ Source or Header  |  1990-12-06  |  4KB  |  206 lines

  1. /* osk.c */
  2.  
  3. /* ------------------------------------------------------------------- *
  4.  |
  5.  | OS9Lib:  stat(), fstat()
  6.  |
  7.  |
  8.  |     Copyright (c) 1988 by Wolfgang Ocker, Puchheim,
  9.  |                           Ulli Dessauer, Germering and
  10.  |                           Reimer Mellin, Muenchen
  11.  |                           (W-Germany)
  12.  |
  13.  |  This  programm can  be  copied and  distributed freely  for any
  14.  |  non-commercial  purposes.   It can only  be  incorporated  into
  15.  |  commercial software with the written permission of the authors.
  16.  |
  17.  |  If you should modify this program, the authors would appreciate
  18.  |  a notice about the changes. Please send a (context) diff or the
  19.  |  complete source to:
  20.  |
  21.  |  address:     Wolfgang Ocker
  22.  |               Lochhauserstrasse 35a
  23.  |               D-8039 Puchheim
  24.  |               West Germany
  25.  |
  26.  |  e-mail:      weo@altger.UUCP, ud@altger.UUCP, ram@altger.UUCP
  27.  |               pyramid!tmpmbx!recco!weo
  28.  |               pyramid!tmpmbx!nitmar!ud
  29.  |               pyramid!tmpmbx!ramsys!ram
  30.  |
  31.  * ----------------------------------------------------------------- */
  32.  
  33. #ifdef OSK
  34.  
  35. #define PATCHLEVEL 1
  36.  
  37. #ifndef VIREC
  38. #include <stdio.h>
  39. #include "osk.h"
  40. #include <modes.h>
  41. #include <errno.h>
  42. #endif
  43. #include <signal.h>
  44. #include <sgstat.h>
  45. #include <sg_codes.h>
  46. #include <direct.h>
  47.  
  48. /*
  49.  * f s t a t
  50.  */
  51. int fstat(fd, buff)
  52.   int         fd;
  53.   struct stat *buff;
  54. {
  55.   struct fildes ftmp;
  56.   struct tm     ttmp;
  57.   struct _sgr   fopt;
  58.  
  59.   if (_gs_gfd(fd, &ftmp, 16) < 0) /* 16 insteat of sizeof(struct fildes)   */
  60.     return(-1);                   /* used due to a bug in stupid os9net */
  61.  
  62.   if (_gs_opt(fd, &fopt) < 0)
  63.     return(-1);
  64.  
  65.   ttmp.tm_year  = (int) ftmp.fd_date[0];
  66.   ttmp.tm_mon   = (int) ftmp.fd_date[1] - 1;
  67.   ttmp.tm_mday  = (int) ftmp.fd_date[2];    
  68.   ttmp.tm_hour  = (int) ftmp.fd_date[3];
  69.   ttmp.tm_min   = (int) ftmp.fd_date[4];
  70.   ttmp.tm_sec   = 0;
  71.   ttmp.tm_isdst = -1;
  72.  
  73.   buff->st_atime = buff->st_mtime = mktime(&ttmp);
  74.  
  75.   ttmp.tm_year  = (int) ftmp.fd_dcr[0];
  76.   ttmp.tm_mon   = (int) ftmp.fd_dcr[1] - 1;
  77.   ttmp.tm_mday  = (int) ftmp.fd_dcr[2];    
  78.   ttmp.tm_hour  = ttmp.tm_min = ttmp.tm_sec = 0;
  79.   ttmp.tm_isdst = -1;
  80.   
  81.   buff->st_ctime = mktime(&ttmp);
  82.  
  83.   memcpy(&(buff->st_size), ftmp.fd_fsize, sizeof(long));  /* misalignment! */
  84.   buff->st_uid   = ftmp.fd_own[1];
  85.   buff->st_gid   = ftmp.fd_own[0];
  86.   buff->st_mode  = ftmp.fd_att;
  87.   buff->st_nlink = ftmp.fd_link;
  88.  
  89.   buff->st_ino   = fopt._sgr_fdpsn;
  90.   buff->st_dev   = fopt._sgr_dvt;
  91.  
  92.   return(0);
  93. }
  94.  
  95. /*
  96.  * s t a t
  97.  */    
  98. int stat(filename, buff)
  99.   char        *filename;
  100.   struct stat *buff;
  101. {
  102.   register int i, ret;
  103.  
  104.   if ((i = open(filename, S_IREAD)) < 0)
  105.     if ((i = open(filename, S_IFDIR | S_IREAD)) < 0)
  106.       return(-1);
  107.  
  108.   ret = fstat(i, buff);
  109.   close(i);
  110.  
  111.   return(ret);
  112. }
  113.  
  114. /*
  115.     unix library functions mist in OSK
  116.     Author: Peter Reinig
  117. */
  118.  
  119. /* NOTE: this version of link() is only capable of renaming files, not true
  120.  * UNIX-style linking.  That's okay, though, because elvis only uses it for
  121.  * renaming.
  122.  */
  123. link(from,to)
  124. char *from,*to;
  125. {
  126.     char *buffer;
  127.     int status;
  128.     char *malloc();
  129.  
  130.     if ((buffer = malloc(strlen(from) + strlen(to) + 12)) == NULL)
  131.         return -1;
  132.     sprintf(buffer,"rename %s %s\n",from,to);
  133.     status = system(buffer);
  134.     free(buffer);
  135.     return status;
  136. }
  137.  
  138. typedef (*procref)();
  139. #define MAX_SIGNAL 10
  140.  
  141. extern exit();
  142.  
  143. static int (*sig_table[MAX_SIGNAL])();
  144. static int _sig_install = 0;
  145.  
  146. sig_handler(sig)
  147. int sig;
  148. {
  149.     if ((int) sig_table[sig] > MAX_SIGNAL)
  150.         sig_table[sig](sig);
  151. }
  152.  
  153. procref signal(sig,func)
  154. int sig;
  155. int (*func)();
  156. {
  157.     int i, (*sav)();
  158.  
  159.     if (!_sig_install) {
  160.         for (i=0; i < MAX_SIGNAL; i++)
  161.             sig_table[i] = exit;
  162.         _sig_install = 1;
  163.         intercept(sig_handler);
  164.     }    
  165.     sav = sig_table[sig];
  166.     switch ((int) func) {
  167.         case SIG_DFL : sig_table[sig] = exit;
  168.                        break;
  169.         case SIG_IGN : sig_table[sig] = 0;
  170.                        break;
  171.         default      : sig_table[sig] = func;
  172.                        break;
  173.     }
  174.     return sav;
  175. }
  176.  
  177. perror(str)
  178. char *str;
  179. {
  180.     static int path = 0;
  181.     if (!path && (path = open("/dd/sys/Errmsg", S_IREAD)) == -1) {
  182.         fprintf(stderr,"Can\'t open error message file\n");
  183.         path = 0;
  184.     }
  185.     if (str && *str) {
  186.         fprintf(stderr,"%s: ",str);
  187.         fflush(stderr);
  188.     }
  189.     prerr(path,(short) errno);
  190. }
  191.  
  192. isatty(fd)
  193. int fd;
  194. {
  195.     struct sgbuf buffer;
  196.     char type;
  197.  
  198.     _gs_opt(fd,&buffer);
  199.     type = buffer.sg_class;
  200.     if (type == DT_SCF)
  201.         return 1;
  202.     else
  203.         return 0;
  204. }
  205. #endif /* OSK */
  206.