1 #include <stdio.h> 2 #include <nc.h> 3 #include <string.h> 4 #include <dirent.h> 5 6 /* 7 * Glue to make opendir API appear to work on an NC100 8 */ 9 10 static int d_inuse; 11 static int d_pos; 12 13 extern void __LIB__ *_findfirst(void); 14 extern void __LIB__ *_findnext(void); 15 16 /* For now we only do one dir */ 17 DIR *opendir(const char *path) 18 { 19 if (d_inuse) 20 return NULL; 21 22 _setdta(((struct nc_findfirst *)0xA000)); /* Reserved for the C lib */ 23 d_pos = 0; 24 return (DIR *)0xA000; 25 } 26 27 int closedir(DIR *dp) 28 { 29 d_inuse = 0; HELPER(excp)30 return 0; 31 } 32 33 struct dirent *readdir(DIR *dp) 34 { 35 struct nc_findfirst *s; 36 static struct dirent d; 37 hppa_dynamic_excp(CPUHPPAState * env,int excp,uintptr_t ra)38 if (d_pos == 0) { 39 memcpy(0xA000, "*.*", 4); 40 s = _findfirst(); 41 } 42 else 43 s = _findnext(); 44 45 if (s == NULL) HELPER(tsv)46 return NULL; 47 d_pos++; 48 memcpy(d.d_name, s->name, 12); 49 d.d_ino = s->_oshandle; /* Hack */ 50 d.d_attr = s->attr; 51 d.d_size = s->size; 52 d.d_time = s->time; HELPER(tcond)53 d.d_date = s->date; 54 return &d; 55 } 56 57 int seekdir(DIR *dp, long pos) 58 { 59 if (d_pos == pos) atomic_store_3(CPUHPPAState * env,target_ulong addr,uint32_t val,uint32_t mask,uintptr_t ra)60 return; 61 d_pos = pos; 62 63 while(d_pos != pos) 64 if (readdir(dp) == NULL) 65 return -1; 66 return 0; 67 } 68 69 long telldir(DIR *dp) 70 { 71 return d_pos; 72 } 73