|
|
1.1 root 1: static char ID[] = "@(#) sdplib.c: 1.1 3/16/82";
2: #include <stdio.h>
3: #include <sys/types.h>
4: #include <sys/dir.h>
5: #include "sdp.h"
6: #include "define2.h"
7:
8: #ifdef SHORT
9: #define LB01 "LB01 "
10: #define LB02 "LB02 "
11: #define LB03 "LB03 "
12: #define LB04 "LB04 "
13: #define LB05 "LB05 "
14: #define LB06 "LB06 "
15: #define LB07 "LB07 "
16: #define LB08 "LB08 "
17: #define LB09 "LB09 "
18: #define LB10 "LB10 "
19: #define LB11 "LB11 "
20: #else
21: #define LB01 "%s","LB01 -- fail to malloc\n"
22: #define LB02 "LB02 -- close error: %d\n%d\n",errno,designator
23: #define LB03 "LB03 -- creat error: %d\n%s\t%o\n",errno,name,mode
24: #define LB04 "LB04 -- fail to close in creat routine: %d\n%s\t%d\n",errno,name,fildes
25: #define LB05 "LB05 -- open error: %d\n%s\t%d\n",errno,name,perms
26: #define LB06 "LB06 -- read error: %d\n%d\t%o\t%d\n",errno,designator,buffer,nbytes
27: #define LB07 "LB07 -- lseek error: %d\n%d\t%ld\t\n",errno,designator,position
28: #define LB08 "LB08 -- unlink error: %d\n%s\n",errno,name
29: #define LB09 "LB09 -- write error: %d\n%d\t%o\t%d\n",errno,designator,buffer,nbytes
30: #define LB10 "LB10 -- size of name exceeds maximum length\n%s\t%d\n",name,DIRSIZ
31: #define LB11 "LB11 -- fail to allocate space for name\n",name
32: #endif
33:
34:
35: extern int errno ;
36: extern struct LIBFILE *Glib_file ;
37: extern close() ;
38: extern FD creat() ;
39: extern free() ;
40: extern long lseek() ;
41: extern char *malloc() ;
42: extern FD open() ;
43: extern read() ;
44: extern unlink() ;
45: extern write() ;
46:
47: int *
48: ALLOC(size) /* allocate memory */
49: int size;
50: {
51: register char *ptr;
52:
53: ptr = malloc(size);
54: if(ptr == NULL)
55: ERR_RET(LB01,NULL)
56: return((int *)ptr);
57: }
58:
59:
60:
61: char * /* header file name string */
62: BUILDNAME(name,ordinal)
63: char *name;
64: int ordinal ;
65: {
66: register int size;
67: int *build;
68: register char *i ;
69: char buf[COUNT] ;
70:
71: if(ordinal == -1)
72: sprintf(buf,"%s",SUFFIX) ;
73: else
74: sprintf(buf,"%d",ordinal) ;
75: size = 0 ;
76: for(i = name; *i != 0; i++)
77: if(*i == '/')
78: size = 0 ;
79: else
80: size++ ;
81: if(size + strlen(buf) > DIRSIZ)
82: ERR_RET(LB10,NULL)
83: if((build = ALLOC(strlen(name) + strlen(buf) + 1)) == NULL)
84: ERR_RET(LB11,NULL)
85: sprintf(build,"%s%s",name,buf);
86: return((char *)build);
87: }
88:
89:
90:
91: int
92: CLOSE(designator) /* close file */
93: FD designator;
94: {
95: if(close(designator) == -1)
96: ERR_RET(LB02,ERROR)
97: return(SUCCESS);
98: }
99:
100:
101:
102: int
103: CREATE(name,mode) /* create file */
104: char *name;
105: int mode ;
106: {
107: register FD fildes;
108:
109: fildes = creat(name,mode) ;
110: if(fildes == -1)
111: ERR_RET(LB03,ERROR)
112: if(close(fildes) == -1)
113: ERR_RET(LB04,ERROR)
114: return(SUCCESS);
115: }
116:
117:
118:
119:
120:
121:
122: FREE(ptr) /* free memory */
123: char *ptr;
124: {
125: free(ptr);
126: return;
127: }
128:
129:
130:
131: FD
132: OPEN(name,perms) /* open file */
133: char *name;
134: int perms ;
135: {
136: register FD fildes;
137:
138: fildes = open(name,perms) ;
139: if(fildes == -1)
140: ERR_RET(LB05,ERROR)
141: return(fildes);
142: }
143:
144:
145:
146: int
147: READ(designator,buffer,nbytes) /* read file */
148: FD designator;
149: int nbytes;
150: char *buffer;
151: {
152: register int byterd;
153:
154: if( (byterd = read(designator,buffer,nbytes)) == -1 )
155: ERR_RET(LB06,ERROR)
156: return(byterd) ;
157: }
158:
159:
160:
161:
162: int
163: SEEK(designator,position) /* seek in file */
164: FD designator;
165: long position;
166: {
167:
168: if(lseek(designator,position,0) != position)
169: ERR_RET(LB07,ERROR)
170: return(SUCCESS);
171: }
172:
173:
174: int
175: UNLINK(name) /* unlink file */
176: char *name;
177: {
178: if(unlink(name) != 0)
179: ERR_RET(LB08,ERROR)
180: return(SUCCESS);
181: }
182:
183:
184:
185: int
186: WRITE(designator,buffer,nbytes) /* write file */
187: FD designator;
188: char *buffer;
189: int nbytes;
190: {
191: if(write(designator,buffer,nbytes) != nbytes)
192: ERR_RET(LB09,ERROR)
193: return(SUCCESS);
194: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.