Reuse, not rework
Home

License Awareness



Highly Reusable Software

By activity
Professions, Sciences, Humanities, Business, ...

User Interface
Text-based, GUI, Audio, Video, Keyboards, Mouse, Images,...

Text Strings
Conversions, tests, processing, manipulation,...

Math
Integer, Floating point, Matrix, Statistics, Boolean, ...

Processing
Algorithms, Memory, Process control, Debugging, ...

Stored Data
Data storage, Integrity, Encryption, Compression, ...

Communications
Networks, protocols, Interprocess, Remote, Client Server, ...

Hard World
Timing, Calendar and Clock, Audio, Video, Printer, Controls...

File System
Management, Filtering, File & Directory access, Viewers, ...


NAME

librock_VSBreadfile - Read the contents of a file into a librock_VSB.
#License - #Source code - #Example Use -

SYNOPSIS

#include <librock/mstruct.h>

const char *
librock_VSBreadfile(struct librock_VSB_s *v, /* Will be VSBrealloc'ed */
                    char *filename);     /* file path */

DESCRIPTION

Reallocate and load in a file. Returns 0 on success, and v->buf will contain the contents of the file, v->inbuf is set to the size of the file. For text processing convenience, a '\0' is in the buffer just beyond the last character from the file.

The file is opened with open() using (O_RDONLY|librock_O_BINARY) flags.

On failure, one the following error explanation strings is returned;

        "E-1-Could not open"
        "E-2-Could not fstat"
        "E-3-Could not realloc"
        "E-4-Read Error.  Incomplete."

Typical use is to initialize a memory block with the contents
of a file.

#ifdef librock_TYPICAL_USE_VSBreadfile
    #include <stdio.h>
    #include <librock/mstruct.h>
    struct librock_VSB_s *v;
    const char *err;
    v = librock_VSBalloc();
    err = librock_VSBreadfile(v,"exec/struct/vsbrf.c");
    if (err) {
        printf("%s\n",err);
        switch(atoi(err+1)) {
            case 1: /* "E-1-Could not open" */
            break;
            case 2: /* "E-2-Could not fstat" */
            break;
            case 3: /* "E-3-Could not realloc" */
            break;
            case 4: /* "E-4-Read Error" */
            break;
        }
    } else {
        printf("Read size: %d\n",v->inbuf);
    }
    librock_VSBfree(v);
#endif

USES

  fstat
  open
  close
  read
  librock_VSBrealloc


LICENSE

  Copyright 1998-2002 Forrest J. Cavalier III, http://www.mibsoftware.com
  Licensed under BSD-ish license, NO WARRANTY. Copies must retain this block.
  License text in <librock/license/librock.txt> librock_LIDESC_HC=12440211096131f5976d36be0cddca4cd9152e45

Source Code

./exec/struct/vsbrf.c (implementation, plus source of this manual page)

This software is part of Librock

Rapid reuse, without rework. Details
This page copyright (C) 2002-2003 Forrest J. Cavalier III, d-b-a Mib Software, Saylorsburg PA 18353, USA

Verbatim copying and distribution of this generated page is permitted in any medium provided that no changes are made.
(The source of this manual page may be covered by a more permissive license which allows modifications.)

Want to help? We welcome comments, patches. -- Need help? Request paid support.