comparison packages/net/tcpip/current/src/lib/tftp_dummy_file.c @ 128:0c2b7be0d798 ecos-sw-2000-10-12

Merge from eCos master repository on 2000-10-12-08:46:24-BST
author jlarmour
date Thu, 12 Oct 2000 20:31:43 +0000
parents ced4577552cd
children
comparison
equal deleted inserted replaced
127:67f0ef5f8ee9 128:0c2b7be0d798
99 4444444444444444444444444444444444 99 4444444444444444444444444444444444
100 5555555555555555555555555555555555 100 5555555555555555555555555555555555
101 6666666666666666666666666666666666 101 6666666666666666666666666666666666
102 "; 102 ";
103 103
104 static char _f0_data[10*1024]; 104 static char _f0_data[1024*1024];
105 static char _f1_data[10*1024]; 105 static char _f1_data[1024*1024];
106 static char _f2_data[10*1024]; 106 static char _f2_data[1024*1024];
107 107
108 static char _name0[256] = "", _name1[256] = "", _name2[256] = ""; 108 static char _name0[256] = "", _name1[256] = "", _name2[256] = "";
109 109
110 static struct _file_info file_list[] = { 110 static struct _file_info file_list[] = {
111 { "uu", _uu_data, sizeof(_uu_data)-1, sizeof(_uu_data)-1}, 111 { "uu", _uu_data, sizeof(_uu_data)-1, sizeof(_uu_data)-1},
113 { _name1, _f1_data, 0, sizeof(_f1_data)}, // Empty file 113 { _name1, _f1_data, 0, sizeof(_f1_data)}, // Empty file
114 { _name2, _f2_data, 0, sizeof(_f2_data)}, // Empty file 114 { _name2, _f2_data, 0, sizeof(_f2_data)}, // Empty file
115 { 0, 0, 0} // End of list 115 { 0, 0, 0} // End of list
116 }; 116 };
117 117
118 static struct _file * 118 static inline struct _file *
119 dummy_fp(int fd) 119 dummy_fp(int fd)
120 { 120 {
121 struct _file *fp; 121 struct _file *fp;
122 if ((fd < 0) || (fd >= NUM_FILES)) return (struct _file *)0; 122 if ((fd < 0) || (fd >= NUM_FILES)) return (struct _file *)0;
123 fp = &files[fd]; 123 fp = &files[fd];
132 int fd; 132 int fd;
133 struct _file *fp; 133 struct _file *fp;
134 struct _file_info *fi; 134 struct _file_info *fi;
135 135
136 fp = files; 136 fp = files;
137 for (fd = 0; fd < NUM_FILES; fd++) { 137 for (fd = 0; fd < NUM_FILES; fd++, fp++) {
138 if (!(fp->flags & FILE_OPEN)) break; 138 if (!(fp->flags & FILE_OPEN)) break;
139 } 139 }
140 if (fd == NUM_FILES) { 140 if (fd == NUM_FILES) {
141 return -1; // No free files 141 return -1; // No free files
142 } 142 }
156 } 156 }
157 } else { 157 } else {
158 // Search for a non-existant file 158 // Search for a non-existant file
159 fi = file_list; 159 fi = file_list;
160 while (fi->name) { 160 while (fi->name) {
161 if (fi->name[0] == '\0') { 161 if (fi->name[0] == '\0' || strcmp(fi->name, fn) == 0) {
162 // Empty slot found 162 if ( !fi->name[0] )
163 strcpy(fi->name, fn); 163 // Empty slot found
164 strcpy(fi->name, fn);
164 fp->pos = fi->data; 165 fp->pos = fi->data;
165 fp->eof = fi->data + fi->size; 166 fp->eof = fi->data + fi->size;
166 fp->file = fi; // So we can update file info later 167 fp->file = fi; // So we can update file info later
167 fp->mode = flags; 168 fp->mode = flags;
168 fp->flags = FILE_OPEN; 169 fp->flags = FILE_OPEN;
213 if (res <= 0) return 0; // End of file 214 if (res <= 0) return 0; // End of file
214 bcopy(fp->pos, buf, res); 215 bcopy(fp->pos, buf, res);
215 fp->pos += res; 216 fp->pos += res;
216 return res; 217 return res;
217 } 218 }
219
220
221 // EOF tftp_dummy_file.c