Lines Matching refs:handle

63    struct nbio_stdio_t* handle = NULL;  in nbio_stdio_open()  local
77 handle = (struct nbio_stdio_t*)malloc(sizeof(struct nbio_stdio_t)); in nbio_stdio_open()
79 if (!handle) in nbio_stdio_open()
82 handle->f = f; in nbio_stdio_open()
90 fseek(handle->f, 0, SEEK_END); in nbio_stdio_open()
91 len = ftell(handle->f); in nbio_stdio_open()
95 handle->mode = mode; in nbio_stdio_open()
103 handle->data = buf; in nbio_stdio_open()
104 handle->len = len; in nbio_stdio_open()
105 handle->progress = handle->len; in nbio_stdio_open()
106 handle->op = -2; in nbio_stdio_open()
108 return handle; in nbio_stdio_open()
111 if (handle) in nbio_stdio_open()
112 free(handle); in nbio_stdio_open()
119 struct nbio_stdio_t *handle = (struct nbio_stdio_t*)data; in nbio_stdio_begin_read() local
120 if (!handle) in nbio_stdio_begin_read()
123 if (handle->op >= 0) in nbio_stdio_begin_read()
129 fseek(handle->f, 0, SEEK_SET); in nbio_stdio_begin_read()
131 handle->op = NBIO_READ; in nbio_stdio_begin_read()
132 handle->progress = 0; in nbio_stdio_begin_read()
137 struct nbio_stdio_t *handle = (struct nbio_stdio_t*)data; in nbio_stdio_begin_write() local
138 if (!handle) in nbio_stdio_begin_write()
141 if (handle->op >= 0) in nbio_stdio_begin_write()
147 fseek(handle->f, 0, SEEK_SET); in nbio_stdio_begin_write()
148 handle->op = NBIO_WRITE; in nbio_stdio_begin_write()
149 handle->progress = 0; in nbio_stdio_begin_write()
155 struct nbio_stdio_t *handle = (struct nbio_stdio_t*)data; in nbio_stdio_iterate() local
157 if (!handle) in nbio_stdio_iterate()
160 if (amount > handle->len - handle->progress) in nbio_stdio_iterate()
161 amount = handle->len - handle->progress; in nbio_stdio_iterate()
163 switch (handle->op) in nbio_stdio_iterate()
166 if (handle->mode == BIO_READ) in nbio_stdio_iterate()
168 amount = handle->len; in nbio_stdio_iterate()
169 fread((char*)handle->data, 1, amount, handle->f); in nbio_stdio_iterate()
172 fread((char*)handle->data + handle->progress, 1, amount, handle->f); in nbio_stdio_iterate()
175 if (handle->mode == BIO_WRITE) in nbio_stdio_iterate()
178 amount = handle->len; in nbio_stdio_iterate()
179 written = fwrite((char*)handle->data, 1, amount, handle->f); in nbio_stdio_iterate()
184 fwrite((char*)handle->data + handle->progress, 1, amount, handle->f); in nbio_stdio_iterate()
188 handle->progress += amount; in nbio_stdio_iterate()
190 if (handle->progress == handle->len) in nbio_stdio_iterate()
191 handle->op = -1; in nbio_stdio_iterate()
192 return (handle->op < 0); in nbio_stdio_iterate()
198 struct nbio_stdio_t *handle = (struct nbio_stdio_t*)data; in nbio_stdio_resize() local
199 if (!handle) in nbio_stdio_resize()
202 if (handle->op >= 0) in nbio_stdio_resize()
207 if (len < handle->len) in nbio_stdio_resize()
213 handle->len = len; in nbio_stdio_resize()
214 handle->progress = len; in nbio_stdio_resize()
215 handle->op = -1; in nbio_stdio_resize()
217 new_data = realloc(handle->data, handle->len); in nbio_stdio_resize()
220 handle->data = new_data; in nbio_stdio_resize()
225 struct nbio_stdio_t *handle = (struct nbio_stdio_t*)data; in nbio_stdio_get_ptr() local
226 if (!handle) in nbio_stdio_get_ptr()
229 *len = handle->len; in nbio_stdio_get_ptr()
230 if (handle->op == -1) in nbio_stdio_get_ptr()
231 return handle->data; in nbio_stdio_get_ptr()
237 struct nbio_stdio_t *handle = (struct nbio_stdio_t*)data; in nbio_stdio_cancel() local
238 if (!handle) in nbio_stdio_cancel()
241 handle->op = -1; in nbio_stdio_cancel()
242 handle->progress = handle->len; in nbio_stdio_cancel()
247 struct nbio_stdio_t *handle = (struct nbio_stdio_t*)data; in nbio_stdio_free() local
248 if (!handle) in nbio_stdio_free()
250 if (handle->op >= 0) in nbio_stdio_free()
255 fclose(handle->f); in nbio_stdio_free()
256 free(handle->data); in nbio_stdio_free()
258 handle->f = NULL; in nbio_stdio_free()
259 handle->data = NULL; in nbio_stdio_free()
260 free(handle); in nbio_stdio_free()