MCPcopy Create free account
hub / github.com/F-Stack/f-stack / gz_open

Function gz_open

freebsd/contrib/zstd/zlibWrapper/gzlib.c:94–270  ·  view source on GitHub ↗

Open a gzip file either by name or file descriptor. */

(path, fd, mode)

Source from the content-addressed store, hash-verified

92
93/* Open a gzip file either by name or file descriptor. */
94local gzFile gz_open(path, fd, mode)
95 const void *path;
96 int fd;
97 const char *mode;
98{
99 gz_statep state;
100 z_size_t len;
101 int oflag;
102#ifdef O_CLOEXEC
103 int cloexec = 0;
104#endif
105#ifdef O_EXCL
106 int exclusive = 0;
107#endif
108
109 /* check input */
110 if (path == NULL)
111 return NULL;
112
113 /* allocate gzFile structure to return */
114 state.state = (gz_state*)malloc(sizeof(gz_state));
115 if (state.state == NULL)
116 return NULL;
117 state.state->size = 0; /* no buffers allocated yet */
118 state.state->want = GZBUFSIZE; /* requested buffer size */
119 state.state->msg = NULL; /* no error message yet */
120
121 /* interpret mode */
122 state.state->mode = GZ_NONE;
123 state.state->level = Z_DEFAULT_COMPRESSION;
124 state.state->strategy = Z_DEFAULT_STRATEGY;
125 state.state->direct = 0;
126 while (*mode) {
127 if (*mode >= '0' && *mode <= '9')
128 state.state->level = *mode - '0';
129 else
130 switch (*mode) {
131 case 'r':
132 state.state->mode = GZ_READ;
133 break;
134#ifndef NO_GZCOMPRESS
135 case 'w':
136 state.state->mode = GZ_WRITE;
137 break;
138 case 'a':
139 state.state->mode = GZ_APPEND;
140 break;
141#endif
142 case '+': /* can't read and write at the same time */
143 free(state.state);
144 return NULL;
145 case 'b': /* ignore -- will request binary anyway */
146 break;
147#ifdef O_CLOEXEC
148 case 'e':
149 cloexec = 1;
150 break;
151#endif

Callers 4

gzopenFunction · 0.70
gzopen64Function · 0.70
gzdopenFunction · 0.70
gzopen_wFunction · 0.70

Calls 4

mallocFunction · 0.85
snprintfFunction · 0.85
gz_resetFunction · 0.70
freeFunction · 0.50

Tested by

no test coverage detected