Imported Debian patch 0.1.5c-1
[samtools.git] / knetfile.h
1 #ifndef KNETFILE_H
2 #define KNETFILE_H
3
4 #include <stdint.h>
5 #include <fcntl.h>
6
7 // FIXME: currently I/O is unbuffered
8
9 #define KNF_TYPE_LOCAL 1
10 #define KNF_TYPE_FTP   2
11 #define KNF_TYPE_HTTP  3
12
13 typedef struct knetFile_s {
14         int type, fd;
15         int64_t offset;
16         char *host;
17
18         // the following are for FTP only
19         int ctrl_fd, pasv_ip[4], pasv_port, max_response, no_reconnect, is_ready;
20         char *response, *retr;
21         int64_t seek_offset; // for lazy seek
22 } knetFile;
23
24 #define knet_tell(fp) ((fp)->offset)
25 #define knet_fileno(fp) ((fp)->fd)
26
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30
31         knetFile *knet_open(const char *fn, const char *mode);
32
33         /* 
34            This only works with local files.
35          */
36         knetFile *knet_dopen(int fd, const char *mode);
37
38         /*
39           If ->is_ready==0, this routine updates ->fd; otherwise, it simply
40           reads from ->fd.
41          */
42         off_t knet_read(knetFile *fp, void *buf, off_t len);
43
44         /*
45           This routine only sets ->offset and ->is_ready=0. It does not
46           communicate with the FTP server.
47          */
48         int knet_seek(knetFile *fp, off_t off, int whence);
49         int knet_close(knetFile *fp);
50
51 #ifdef __cplusplus
52 }
53 #endif
54
55 #endif