* adfInitDumpDevice * */
| 43 | * |
| 44 | */ |
| 45 | RETCODE adfInitDumpDevice(struct Device* dev, char* name, BOOL ro) |
| 46 | { |
| 47 | struct nativeDevice* nDev; |
| 48 | int32_t size; |
| 49 | |
| 50 | nDev = (struct nativeDevice*)dev->nativeDev; |
| 51 | |
| 52 | nDev = (struct nativeDevice*)malloc(sizeof(struct nativeDevice)); |
| 53 | if (!nDev) { |
| 54 | (*adfEnv.eFct)("adfInitDumpDevice : malloc"); |
| 55 | return RC_MALLOC; |
| 56 | } |
| 57 | dev->nativeDev = nDev; |
| 58 | |
| 59 | dev->readOnly = ro; |
| 60 | errno = 0; |
| 61 | if (!ro) { |
| 62 | nDev->fd = fopen(name,"rb+"); |
| 63 | /* force read only */ |
| 64 | if (!nDev->fd && (errno==EACCES || errno==EROFS) ) { |
| 65 | nDev->fd = fopen(name,"rb"); |
| 66 | dev->readOnly = TRUE; |
| 67 | if (nDev->fd) |
| 68 | (*adfEnv.wFct)("myInitDevice : fopen, read-only mode forced"); |
| 69 | } |
| 70 | } |
| 71 | else |
| 72 | /* read only requested */ |
| 73 | nDev->fd = fopen(name,"rb"); |
| 74 | |
| 75 | if (!nDev->fd) { |
| 76 | free(nDev); |
| 77 | (*adfEnv.eFct)("myInitDevice : fopen"); |
| 78 | return RC_ERROR; |
| 79 | } |
| 80 | |
| 81 | /* determines size */ |
| 82 | fseek(nDev->fd, 0, SEEK_END); |
| 83 | size = ftell(nDev->fd); |
| 84 | fseek(nDev->fd, 0, SEEK_SET); |
| 85 | |
| 86 | dev->size = size; |
| 87 | |
| 88 | return RC_OK; |
| 89 | } |
| 90 | |
| 91 | |
| 92 | /* |