! Truncate an open file * * @param[in,out] r newlib reentrancy struct * @param[in] fd Pointer to archive_file_t * @param[in] len Length to truncate file to * * @returns 0 for success * @returns -1 for error */
| 1242 | * @returns -1 for error |
| 1243 | */ |
| 1244 | static int |
| 1245 | archive_ftruncate(struct _reent *r, |
| 1246 | void *fd, |
| 1247 | off_t len) |
| 1248 | { |
| 1249 | Result rc; |
| 1250 | |
| 1251 | /* get pointer to our data */ |
| 1252 | archive_file_t *file = (archive_file_t*)fd; |
| 1253 | |
| 1254 | /* make sure length is non-negative */ |
| 1255 | if(len < 0) |
| 1256 | { |
| 1257 | r->_errno = EINVAL; |
| 1258 | return -1; |
| 1259 | } |
| 1260 | |
| 1261 | /* set the new file size */ |
| 1262 | rc = FSFILE_SetSize(file->fd, len); |
| 1263 | if(R_SUCCEEDED(rc)) |
| 1264 | return 0; |
| 1265 | |
| 1266 | r->_errno = archive_translate_error(rc); |
| 1267 | return -1; |
| 1268 | } |
| 1269 | |
| 1270 | /*! Synchronize a file to media |
| 1271 | * |
nothing calls this directly
no test coverage detected