IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 12072


Ignore:
Timestamp:
Feb 26, 2007, 5:31:56 PM (19 years ago)
Author:
jhoblitt
Message:

add psSlurpFilename()

Location:
trunk/psLib/src/sys
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/sys/psSlurp.c

    r11617 r12072  
    55 *  @author Joshua Hoblitt, University of Hawaii
    66 *
    7  *  @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
    8  *  @date $Date: 2007-02-03 05:54:08 $
     7 *  @version $Revision: 1.9 $ $Name: not supported by cvs2svn $
     8 *  @date $Date: 2007-02-27 03:31:56 $
    99 *
    1010 *  Copyright 2006 University of Hawaii
     
    1717#include <stdio.h>
    1818#include <unistd.h>
     19#include <sys/types.h>
     20#include <sys/stat.h>
     21#include <fcntl.h>
    1922
    2023#include "psType.h"
     24#include "psAssert.h"
    2125#include "psError.h"
    2226#include "psSlurp.h"
     
    5660}
    5761
     62
    5863psString psSlurpFile(FILE *stream)
    5964{
    6065    return psSlurpFD(fileno(stream));
    6166}
     67
     68
     69psString psSlurpFilename(const char *filename)
     70{
     71    PS_ASSERT_PTR_NON_NULL(filename, NULL);
     72
     73    int fd = open(filename, O_RDONLY);
     74    if (fd < 0) {
     75        psError(PS_ERR_IO, true, "Failed to open specified file, %s\n", filename);
     76        return NULL;
     77    }
     78
     79    psString text = psSlurpFD(fd);
     80
     81    if (close(fd) != 0) {
     82        psError(PS_ERR_IO, true, "Failed to close specified file, %s\n", filename);
     83        psFree(text);
     84        return NULL;
     85    }
     86
     87    return text;
     88}
  • trunk/psLib/src/sys/psSlurp.h

    r11695 r12072  
    44 * @author Joshua Hoblitt, University of Hawaii
    55 *
    6  * @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
    7  * @date $Date: 2007-02-08 01:59:47 $
     6 * @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
     7 * @date $Date: 2007-02-27 03:31:56 $
    88 */
    99
     
    2424                    );
    2525
     26// Read ("slurp") a file (specified by filename)
     27// and return a string containing the entire file.
     28psString psSlurpFilename(const char *filename // Filename
     29                    );
     30
    2631/// @}
    2732#endif
Note: See TracChangeset for help on using the changeset viewer.