filesystem: QNX should use SDL_LoadFile() instead of rolling it from scratch.
authorRyan C. Gordon <icculus@icculus.org>
Thu, 17 Aug 2017 02:58:46 -0400
changeset 1131018bc7f7649d4
parent 11309 e421d01ce5bf
child 11311 67c8d5f92a29
filesystem: QNX should use SDL_LoadFile() instead of rolling it from scratch.
src/filesystem/unix/SDL_sysfilesystem.c
     1.1 --- a/src/filesystem/unix/SDL_sysfilesystem.c	Thu Aug 17 01:25:48 2017 -0400
     1.2 +++ b/src/filesystem/unix/SDL_sysfilesystem.c	Thu Aug 17 02:58:46 2017 -0400
     1.3 @@ -43,36 +43,7 @@
     1.4  #include "SDL_filesystem.h"
     1.5  
     1.6  /* QNX's /proc/self/exefile is a text file and not a symlink. */
     1.7 -#if defined(__QNXNTO__)
     1.8 -static char *
     1.9 -readWholeFile(const char *path)
    1.10 -{
    1.11 -    char *retval = (char *) SDL_malloc(PATH_MAX+1);
    1.12 -    if (retval != NULL)
    1.13 -    {
    1.14 -        const int fd = open(path, O_RDONLY);
    1.15 -        const ssize_t br = (fd == -1) ? -1 : read(fd, retval, PATH_MAX);
    1.16 -        char *ptr;
    1.17 -
    1.18 -        if (fd != -1)
    1.19 -            close(fd);
    1.20 -
    1.21 -        if ((br < 0) || (br > PATH_MAX))
    1.22 -        {
    1.23 -            free(retval);
    1.24 -            return NULL;
    1.25 -        } /* if */
    1.26 -
    1.27 -        retval[br] = '\0';
    1.28 -
    1.29 -        ptr = (char *) SDL_realloc(retval, br + 1);
    1.30 -        if (ptr != NULL)  /* just shrinking buffer; don't care if it failed. */
    1.31 -            retval = ptr;
    1.32 -    } /* else */
    1.33 -
    1.34 -    return retval;
    1.35 -}
    1.36 -#else
    1.37 +#if !defined(__QNXNTO__)
    1.38  static char *
    1.39  readSymLink(const char *path)
    1.40  {
    1.41 @@ -159,7 +130,7 @@
    1.42  #elif defined(__NETBSD__)
    1.43          retval = readSymLink("/proc/curproc/exe");
    1.44  #elif defined(__QNXNTO__)
    1.45 -        retval = readWholeFile("/proc/self/exefile");
    1.46 +        retval = SDL_LoadFile("/proc/self/exefile", NULL);
    1.47  #else
    1.48          retval = readSymLink("/proc/self/exe");  /* linux. */
    1.49          if (retval == NULL) {