source: lib/ior-stdio.c @ 15e9390

4.0.1-hotfixescachetimestampsdevelopdpdk-ndagetsilivegetfragoffhelplibtrace4ndag_formatpfringrc-4.0.1rc-4.0.2rc-4.0.3rc-4.0.4ringdecrementfixringperformanceringtimestampfixes
Last change on this file since 15e9390 was cf30639, checked in by Perry Lorier <perry@…>, 12 years ago

Threading cleanups (and some memory leaks addressed)

  • Property mode set to 100644
File size: 1.1 KB
Line 
1#include "wandio.h"
2#include <sys/types.h>
3#include <sys/stat.h>
4#include <fcntl.h>
5#include <stdlib.h>
6#include <unistd.h>
7#include <string.h>
8
9struct stdio_t {
10        int fd;
11};
12
13extern io_source_t stdio_source;
14
15#define DATA(io) ((struct stdio_t *)((io)->data))
16
17io_t *stdio_open(const char *filename)
18{
19        io_t *io = malloc(sizeof(io_t));
20        io->data = malloc(sizeof(struct stdio_t));
21
22        if (strcmp(filename,"-") == 0)
23                DATA(io)->fd = 0; /* STDIN */
24        else
25                DATA(io)->fd = open(filename,O_RDONLY);
26        io->source = &stdio_source;
27
28        if (DATA(io)->fd == -1) {
29                free(io);
30                return NULL;
31        }
32
33        return io;
34}
35
36static off_t stdio_read(io_t *io, void *buffer, off_t len)
37{
38        return read(DATA(io)->fd,buffer,len);
39}
40
41static off_t stdio_tell(io_t *io)
42{
43        return lseek(DATA(io)->fd, 0, SEEK_CUR);
44}
45
46static off_t stdio_seek(io_t *io, off_t offset, int whence)
47{
48        return lseek(DATA(io)->fd, offset, whence);
49}
50
51static void stdio_close(io_t *io)
52{
53        close(DATA(io)->fd);
54        free(io->data);
55        free(io);
56}
57
58io_source_t stdio_source = {
59        "stdio",
60        stdio_read,
61        NULL,
62        stdio_tell,
63        stdio_seek,
64        stdio_close
65};
66
Note: See TracBrowser for help on using the repository browser.