-int fileio_open(fileio_t *fileio, char *url, enum fileio_access access, enum fileio_type type)
-{
- int retval = ERROR_OK;
- char *resource_identifier = NULL;
-
- /* try to identify file location */
- if ((resource_identifier = strstr(url, "bootp://")) && (resource_identifier == url))
- {
- ERROR("bootp resource location isn't supported yet");
- return ERROR_FILEIO_RESOURCE_TYPE_UNKNOWN;
- }
- else if ((resource_identifier = strstr(url, "tftp://")) && (resource_identifier == url))
- {
- ERROR("tftp resource location isn't supported yet");
- return ERROR_FILEIO_RESOURCE_TYPE_UNKNOWN;
- }
- else
- {
- /* default to local files */
- fileio->location = FILEIO_LOCAL;
- }
-
- fileio->type = type;
- fileio->access = access;
- fileio->url = strdup(url);
-
- switch (fileio->location)
- {
- case FILEIO_LOCAL:
- retval = fileio_open_local(fileio);
- break;
- default:
- ERROR("BUG: should never get here");
- exit(-1);
+ file_size = 0;
+
+ if ((fileio->access != FILEIO_WRITE) || (fileio->access == FILEIO_READWRITE)) {
+ /* NB! Here we use fseek() instead of stat(), since stat is a
+ * more advanced operation that might not apply to e.g. a disk path
+ * that refers to e.g. a tftp client */
+ int result, result2;
+
+ result = fseek(fileio->file, 0, SEEK_END);
+
+ file_size = ftell(fileio->file);
+
+ result2 = fseek(fileio->file, 0, SEEK_SET);
+
+ if ((file_size < 0) || (result < 0) || (result2 < 0)) {
+ fileio_close_local(fileio);
+ return ERROR_FILEIO_OPERATION_FAILED;
+ }