helper/fileio: Use size_t for file size.
[openocd.git] / src / helper / fileio.c
index c6f45e6ba78bb23d8dec0bcdb00abe2b5ee4ed15..9d3931356e706120aa67f57febcd5ccda1f2d41c 100644 (file)
@@ -34,7 +34,7 @@
 
 struct fileio_internal {
        char *url;
-       ssize_t size;
+       size_t size;
        enum fileio_type type;
        enum fileio_access access;
        FILE *file;
@@ -44,6 +44,7 @@ static inline int fileio_close_local(struct fileio_internal *fileio);
 static inline int fileio_open_local(struct fileio_internal *fileio)
 {
        char file_access[4];
+       ssize_t file_size;
 
        switch (fileio->access) {
                case FILEIO_READ:
@@ -78,6 +79,8 @@ static inline int fileio_open_local(struct fileio_internal *fileio)
                return ERROR_FILEIO_OPERATION_FAILED;
        }
 
+       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
@@ -86,16 +89,17 @@ static inline int fileio_open_local(struct fileio_internal *fileio)
 
                result = fseek(fileio->file, 0, SEEK_END);
 
-               fileio->size = ftell(fileio->file);
+               file_size = ftell(fileio->file);
 
                result2 = fseek(fileio->file, 0, SEEK_SET);
 
-               if ((fileio->size < 0) || (result < 0) || (result2 < 0)) {
+               if ((file_size < 0) || (result < 0) || (result2 < 0)) {
                        fileio_close_local(fileio);
                        return ERROR_FILEIO_OPERATION_FAILED;
                }
-       } else
-               fileio->size = 0x0;
+       }
+
+       fileio->size = file_size;
 
        return ERROR_OK;
 }
@@ -245,9 +249,10 @@ int fileio_write_u32(struct fileio *fileio_p, uint32_t data)
  * Avoiding the seek on startup opens up for using streams.
  *
  */
-int fileio_size(struct fileio *fileio_p, int *size)
+int fileio_size(struct fileio *fileio_p, size_t *size)
 {
        struct fileio_internal *fileio = fileio_p->fp;
        *size = fileio->size;
+
        return ERROR_OK;
 }

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)