RSA BSAFE Micro Edition Suite

Streamlined security for mobile and embedded devices

Search  Print

File Functions

This section documents the functions that provide a platform-independent interface for file operations.
note.gif
Not all operating systems support file operations.

Functions

long BIO_set_fp (BIO *bio, char *fp, long flags)
 Sets the file pointer fp to be used with the BIO bio. More...

long BIO_get_fp (BIO *bio, char *fp)
 Returns the file pointer associated with the BIO bio. More...

int BIO_seek (BIO *bio, long offset)
 Moves the current position in the BIO bio. More...

int BIO_tell (BIO *bio)
 Retrieves the current position in the BIO bio. More...

long BIO_read_filename (BIO *bio, char *name)
 Opens the file name name for reading on the BIO bio. More...

long BIO_write_filename (BIO *bio, char *name)
 Opens the file name name for writing on the BIO bio. More...

long BIO_append_filename (BIO *bio, char *name)
 Opens the file name name for writing on the BIO bio after End-of-File (EOF). More...

long BIO_rw_filename (BIO *bio, char *name)
 Opens the file name name on the BIO bio for both reading and writing. More...

BIO* R_CDECL BIO_new_file (char *filename, char *mode)
 Creates a file BIO descriptor filename with a file opening mode of mode. More...

BIO* R_CDECL BIO_new_fp (FILE *stream, int close_flag)
 Creates a new file BIO descriptor file pointer. More...

int R_CDECL BIO_open_file (BIO *bio, char *name, char *mode)
 Opens the file name with a file opening mode of mode. More...


Function Documentation

long BIO_append_filename BIO   bio,
char *    name
;
 

Opens the file name name for writing on the BIO bio after End-of-File (EOF).

Parameters:
bio [In, Out] A reference to the BIO.
name [In] A reference to the file name.
Returns:
1 indicates success.
<=0 indicates error.

long BIO_get_fp BIO   bio,
char *    fp
;
 

Returns the file pointer associated with the BIO bio.

Parameters:
bio [In] A reference to the BIO.
fp [Out] A reference to the file pointer.
It cannot be NULL.
Returns:
1

BIO* R_CDECL BIO_new_file char *    filename,
char *    mode
;
 

Creates a file BIO descriptor filename with a file opening mode of mode. The function is called in a similar manner to BIO_open_file(). The main difference is that this function returns a BIO.

Parameters:
filename [In] The file name.
mode [In] The file opening mode. One of:
Mode Description
a or ab Indicates append open or create file for writing at End-of-File (EOF).
a+ or ab+ or a+b Indicates append open or create file for update, writing at EOF.
r or rb Open file for reading.
r+ or rb+ or r+b Indicates open file for update (reading and writing).
w or wb Indicates truncate to zero length or create file for writing.
w+ or wb+ or w+b Indicates truncate to zero length or create file for update.

Returns:
The BIO reference.
NULL indicates error.
note.gif
All methods are implemented for this type of BIO.
This function is not available on platforms that do not support file operations.
Samples:
cert.c, cert_smpl.c, cm_dgst.c, cm_env.c, cm_env_sm.c, cm_env_strm.c, cm_env_strm_membio.c, cm_open_strm.c, cm_open_strm_cb.c, cm_open_strm_membio.c, cm_sign.c, cm_sign_dgst.c, cm_sign_sm.c, cm_sign_strm.c, cm_strm.c, cm_vfy_strm_cb.c, ext.c, ocsp_req_create.c, pkey.c, r_asym.c, r_gnrt.c, r_sign.c, req.c, req_smpl.c, reqgen.c, and ss_cert_smpl.c.

BIO* R_CDECL BIO_new_fp FILE *    stream,
int    close_flag
;
 

Creates a new file BIO descriptor file pointer. close_flag indicates whether BIO_free() should close the file pointer.

Parameters:
stream [In] The file reference.
close_flag [In] The close flag. One of:
  • BIO_CLOSE.
  • BIO_NOCLOSE.
  • Returns:
    The BIO reference.
    NULL indicates error.
    note.gif
    When creating a file pointer BIO for stdin, stdout or stderr, the file pointer is not normally closed when the BIO is freed.
    This function is not available on platforms that do not support file operations.
    All methods are implemented for this type of BIO.
    See also:
    BIO_free().
    Example:

    /* $Id: bio_new_fp.c,v 1.2 2003/05/23 05:20:02 sparki Exp $ */
    /*
     * Copyright (C) 1998-2003 RSA Security Inc. All rights reserved. 
     *
     * This work contains proprietary information of RSA Security. 
     * Distribution is limited to authorized licensees of RSA 
     * Security. Any unauthorized reproduction, distribution or 
     * modification of this work is strictly prohibited.
     */
    int ret;
    char *fname;
    
    /* open a log file */
    bio_err = BIO_new_fp(stderr, BIO_NOCLOSE);
    
    /* open a data file to read from */
    fname = "old_data.dat";
    bio = BIO_new_file(fname, "r");
    if (bio == NULL)
    {
        BIO_printf(bio_err, "Failed to open file %s\n", fname);
        ERR_print_errors(bio_err);
        
        /* error handling */
    }
    
    /* process data from the BIO */
    
    /* open a new data file to process */
    fname = "new_data.dat";
    ret = BIO_open_file(bio, fname, "r");
    
    /* check for failure */
    if (ret == 0)
    {
        BIO_printf(bio_err, "Failed to open file %s\n", fname);
        ERR_print_errors(bio_err);
        
        /* BIO state may be undefined so free it now */
        BIO_free(bio);
        bio = NULL;
    }
    /* process new data */
    
    Samples:
    bio_client.c, bio_server.c, cache_server.c, cert.c, cert_smpl.c, cm.c, cm_adv.c, cm_dgst.c, cm_env.c, cm_env_sm.c, cm_env_strm.c, cm_env_strm_membio.c, cm_open.c, cm_open_strm.c, cm_open_strm_cb.c, cm_open_strm_membio.c, cm_sign.c, cm_sign_dgst.c, cm_sign_sm.c, cm_sign_strm.c, cm_smpl.c, cm_strm.c, cm_type.c, cm_vfy_strm_cb.c, evpkey2rpkey.c, ext.c, frombuf.c, nbio_client.c, nbio_server.c, ocsp_req_create.c, ocsp_req_print.c, ocsp_resp_ext.c, ocsp_resp_find_key.c, ocsp_resp_print.c, ocsp_resp_vfy.c, p7ssl_client.c, p7ssl_server.c, pkey.c, r_asym.c, r_asym_buf.c, r_asym_items.c, r_ciph.c, r_dgst.c, r_gnrt.c, r_hmac.c, r_random.c, r_sign.c, r_version.c, rcert2sslcert.c, req.c, req_smpl.c, reqgen.c, reslist_set.c, s_crl_check.c, s_crl_verify.c, sock_client.c, sock_server.c, ss_cert_smpl.c, ssl_client.c, ssl_server.c, sslcert2rcert.c, store.c, thread.c, verify.c, vfy_adv.c, vfy_bc.c, and vfy_smpl.c.

    int R_CDECL BIO_open_file BIO   bio,
    char *    name,
    char *    mode
    ;
     

    Opens the file name with a file opening mode of mode. The file can be accessed via the BIO structure bio.

    Parameters:
    bio [In, Out] The BIO reference.
    name [In] The file name to open.
    mode [In] The file opening mode. One of:
    Mode Description
    a or ab or at Append open or create file for writing at End-of-File (EOF) in binary or text mode.
    a+ or ab+ or a+b or at+ or a+t Append open or create file for update (in binary or text mode).
    r or rb or rt Open file for reading (in binary or text mode).
    r+ or rb+ or r+b or rt+ or r+t Open file for update (reading and writing) in binary or text mode.
    w or wb or wt Truncate to zero length or create file for writing (in binary or text mode).
    w+ or wb+ or w+b or wt+ or w+t Truncate to zero length or create file for update (in binary or text mode).

    Returns:
    1 indicates success.
    0 indicates error.
    note.gif
    As the file has BIO_CLOSE associated with it, it will be closed if the BIO is freed. In the event of an error, the BIO's file is closed.

    long BIO_read_filename BIO   bio,
    char *    name
    ;
     

    Opens the file name name for reading on the BIO bio.

    Parameters:
    bio [In, Out] A reference to the BIO.
    name [In] A reference to the file name.
    Returns:
    1 indicates success.
    <=0 indicates error.
    See also:
    BIO_write_filename().

    long BIO_rw_filename BIO   bio,
    char *    name
    ;
     

    Opens the file name name on the BIO bio for both reading and writing.

    Parameters:
    bio [In, Out] A reference to the BIO.
    name [In] A reference to the file name.
    Returns:
    1 indicates success.
    <=0 indicates error.
    Example:

    /* $Id: bio_rw_filename.c,v 1.2 2003/05/23 05:20:02 sparki Exp $ */
    /*
     * Copyright (C) 1998-2003 RSA Security Inc. All rights reserved. 
     *
     * This work contains proprietary information of RSA Security. 
     * Distribution is limited to authorized licensees of RSA 
     * Security. Any unauthorized reproduction, distribution or 
     * modification of this work is strictly prohibited.
     */
    long ret;
    BIO *bio;
    char *name;
    char *data[BUFLEN];
    
    ret = BIO_rw_filename(bio,name);
    
    /* read data */
    BIO_read(bio,data,BUFLEN);
    
    /* make changes to file and write the file */
    BIO_seek(bio,0);
    BIO_write(bio,data,BUFLEN);
    

    int BIO_seek BIO   bio,
    long    offset
    ;
     

    Moves the current position in the BIO bio. This is the BIO version of the standard C functions fseek and lseek. This version only allows an offset from the beginning of a file.

    Parameters:
    bio [In] A reference to the BIO.
    offset [In] The offset from the start of the BIO.
    Returns:
    1 indicates success.
    <=0 indicates error.
    note.gif
    This function should only be used with file BIOs.
    Example:

    /* $Id: bio_seek.c,v 1.2 2003/05/23 05:20:02 sparki Exp $ */
    /*
     * Copyright (C) 1998-2003 RSA Security Inc. All rights reserved. 
     *
     * This work contains proprietary information of RSA Security. 
     * Distribution is limited to authorized licensees of RSA 
     * Security. Any unauthorized reproduction, distribution or 
     * modification of this work is strictly prohibited.
     */
    long ret;
    BIO *bio;
    long offset;
    char *data[BUFLEN];
    
    ret = BIO_seek(bio, offset);
    bio_READ(bio, data, BUFLEN);
    
    /* reset BIO to start of input */
    BIO_seek(bio,0);
    

    long BIO_set_fp BIO   bio,
    char *    fp,
    long    flags
    ;
     

    Sets the file pointer fp to be used with the BIO bio.

    Parameters:
    bio [In] A reference to the BIO.
    fp [In] A reference to the file pointer.
    flags [In] The flags to set against the BIO.
    Returns:
    1

    int BIO_tell BIO   bio ;
     

    Retrieves the current position in the BIO bio. This is the BIO version of the standard C ftell function.

    Parameters:
    bio [In] A reference to the BIO.
    Returns:
    >=0 indicates the file offset position.
    -1 indicates error.
    Example:

    /* $Id: bio_tell.c,v 1.2 2003/05/23 05:20:02 sparki Exp $ */
    /*
     * Copyright (C) 1998-2003 RSA Security Inc. All rights reserved. 
     *
     * This work contains proprietary information of RSA Security. 
     * Distribution is limited to authorized licensees of RSA 
     * Security. Any unauthorized reproduction, distribution or 
     * modification of this work is strictly prohibited.
     */
    int ret;
    BIO *bio;
    char *data;
    long b_offset;
    
    ret = BIO_tell(bio);
    
    /* read all data from the start of BIO to the current position */
    b_offset = BIO_tell(bio);
    if (b_offset > 0)
    {
        data = Malloc(b_offset);
        BIO_seek(bio,0);
        BIO_read(bio,data,b_offset);
    }
    

    long BIO_write_filename BIO   bio,
    char *    name
    ;
     

    Opens the file name name for writing on the BIO bio.

    Parameters:
    bio [In, Out] A reference to the BIO.
    name [In] A reference to the file name.
    Returns:
    1 indicates success.
    <=0 indicates error.
    See also:
    BIO_read_filename().


    Copyright (c) 1999-2005 RSA Security Inc. All rights reserved. 072-001001-2100-001-000 - 2.1