Changeset baef9df


Ignore:
Timestamp:
04/20/10 14:08:27 (11 years ago)
Author:
Perry Lorier <perry@…>
Branches:
4.0.1-hotfixes, cachetimestamps, develop, dpdk-ndag, etsilive, getfragoff, help, libtrace4, master, ndag_format, pfring, rc-4.0.1, rc-4.0.2, rc-4.0.3, rc-4.0.4, ringdecrementfix, ringperformance, ringtimestampfixes
Children:
5b8f9ee
Parents:
8ed31c2
Message:

Add back support for opening files for write with arbitary flags

Location:
lib
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • lib/iow-stdio.c

    r22cdd39 rbaef9df  
    5959#define DATA(iow) ((struct stdiow_t *)((iow)->data))
    6060
    61 static int safe_open(const char *filename)
     61static int safe_open(const char *filename, int flags)
    6262{
    6363        int fd;
     
    6565#ifdef O_DIRECT
    6666        fd = open(filename,
    67                 O_WRONLY
     67                flags
     68                |O_WRONLY
    6869                |O_CREAT
    6970                |O_TRUNC
     
    7576/* If that failed (or we don't support O_DIRECT) try opening without */
    7677        fd = open(filename,
    77                 O_WRONLY
     78                flags
     79                |O_WRONLY
    7880                |O_CREAT
    7981                |O_TRUNC,
     
    8486}
    8587
    86 iow_t *stdio_wopen(const char *filename)
     88iow_t *stdio_wopen(const char *filename,int flags)
    8789{
    8890        iow_t *iow = malloc(sizeof(iow_t));
     
    9395                DATA(iow)->fd = 1; /* STDOUT */
    9496        else {
    95                 DATA(iow)->fd = safe_open(filename);
     97                DATA(iow)->fd = safe_open(filename, flags);
    9698        }
    9799
  • lib/wandio.c

    rb5af22c rbaef9df  
    112112#define READ_TRACE 0
    113113#define WRITE_TRACE 0
     114#define PIPELINE_TRACE 0
     115
     116#if PIPELINE_TRACE
     117#define DEBUG_PIPELINE(x) fprintf(stderr,"PIPELINE: %s\n",x)
     118#else
     119#define DEBUG_PIPELINE(x)
     120#endif
    114121
    115122io_t *wandio_create(const char *filename)
     
    121128         * the file */
    122129
     130        DEBUG_PIPELINE("stdio");
     131        DEBUG_PIPELINE("peek");
    123132        io_t *io = peek_open(stdio_open(filename));
    124133        char buffer[1024];
     
    130139        /* Auto detect gzip compressed data */
    131140        if (len>=2 && buffer[0] == '\037' && buffer[1] == '\213') {
     141                DEBUG_PIPELINE("zlib");
    132142                io = zlib_open(io);
    133143        }
    134144        /* Auto detect compress(1) compressed data (gzip can read this) */
    135145        if (len>=2 && buffer[0] == '\037' && buffer[1] == '\235') {
     146                DEBUG_PIPELINE("zlib");
    136147                io = zlib_open(io);
    137148        }
     
    140151        /* Auto detect bzip compressed data */
    141152        if (len>=3 && buffer[0] == 'B' && buffer[1] == 'Z' && buffer[2] == 'h') {
     153                DEBUG_PIPELINE("bzip");
    142154                io = bz_open(io);
    143155        }
     
    147159         * to read the data */
    148160
    149         if (use_threads)
     161        if (use_threads) {
     162                DEBUG_PIPELINE("thread");
    150163                io = thread_open(io);
     164        }
    151165       
     166        DEBUG_PIPELINE("peek");
    152167        return peek_open(io);
    153168}
     
    174189{
    175190        off_t ret;
     191        ret=io->source->read(io,buffer,len);
    176192#if READ_TRACE
    177         fprintf(stderr,"read(%s): %d bytes\n",io->source->name, (int)len);
    178 #endif
    179         ret=io->source->read(io,buffer,len);
     193        fprintf(stderr,"%p: read(%s): %d bytes = %d\n",io,io->source->name, (int)len,(int)ret);
     194#endif
    180195        return ret;
    181196}
     
    207222        assert ( compression_level >= 0 && compression_level <= 9 );
    208223
    209         iow=stdio_wopen(filename);
     224        iow=stdio_wopen(filename, flags);
    210225
    211226        /* We prefer zlib if available, otherwise we'll use bzip. If neither
  • lib/wandio.h

    rb5af22c rbaef9df  
    6060        const char *ext;
    6161        /** Internal type identifying the compression method */
    62         int compress_flag;
     62        int compress_type;
    6363};
    6464
     
    187187iow_t *lzo_wopen(iow_t *child, int compress_level);
    188188iow_t *thread_wopen(iow_t *child);
    189 iow_t *stdio_wopen(const char *filename);
     189iow_t *stdio_wopen(const char *filename, int fileflags);
    190190
    191191/* @} */
Note: See TracChangeset for help on using the changeset viewer.