Lines Matching refs:data
99 static char *ps_files_path_create(char *buf, size_t buflen, ps_files *data, const char *key) in ps_files_path_create() argument
107 if (key_len <= data->dirdepth || in ps_files_path_create()
108 buflen < (strlen(data->basedir) + 2 * data->dirdepth + key_len + 5 + sizeof(FILE_PREFIX))) { in ps_files_path_create()
113 memcpy(buf, data->basedir, data->basedir_len); in ps_files_path_create()
114 n = data->basedir_len; in ps_files_path_create()
116 for (i = 0; i < (int)data->dirdepth; i++) { in ps_files_path_create()
133 static void ps_files_close(ps_files *data) in ps_files_close() argument
135 if (data->fd != -1) { in ps_files_close()
139 flock(data->fd, LOCK_UN); in ps_files_close()
141 close(data->fd); in ps_files_close()
142 data->fd = -1; in ps_files_close()
146 static void ps_files_open(ps_files *data, const char *key TSRMLS_DC) in ps_files_open() argument
150 if (data->fd < 0 || !data->lastkey || strcmp(key, data->lastkey)) { in ps_files_open()
151 if (data->lastkey) { in ps_files_open()
152 efree(data->lastkey); in ps_files_open()
153 data->lastkey = NULL; in ps_files_open()
156 ps_files_close(data); in ps_files_open()
163 if (!ps_files_path_create(buf, sizeof(buf), data, key)) { in ps_files_open()
167 data->lastkey = estrdup(key); in ps_files_open()
169 data->fd = VCWD_OPEN_MODE(buf, O_CREAT | O_RDWR | O_BINARY, data->filemode); in ps_files_open()
171 if (data->fd != -1) { in ps_files_open()
177 if (fstat(data->fd, &sbuf)) { in ps_files_open()
178 close(data->fd); in ps_files_open()
188 close(data->fd); in ps_files_open()
193 flock(data->fd, LOCK_EX); in ps_files_open()
199 if (fcntl(data->fd, F_SETFD, FD_CLOEXEC)) { in ps_files_open()
200 …L TSRMLS_CC, E_WARNING, "fcntl(%d, F_SETFD, FD_CLOEXEC) failed: %s (%d)", data->fd, strerror(errno… in ps_files_open()
262 #define PS_FILES_DATA ps_files *data = PS_GET_MOD_DATA()
266 ps_files *data; in PS_OPEN_FUNC() local
315 data = ecalloc(1, sizeof(*data)); in PS_OPEN_FUNC()
317 data->fd = -1; in PS_OPEN_FUNC()
318 data->dirdepth = dirdepth; in PS_OPEN_FUNC()
319 data->filemode = filemode; in PS_OPEN_FUNC()
320 data->basedir_len = strlen(save_path); in PS_OPEN_FUNC()
321 data->basedir = estrndup(save_path, data->basedir_len); in PS_OPEN_FUNC()
323 PS_SET_MOD_DATA(data); in PS_OPEN_FUNC()
332 ps_files_close(data); in PS_CLOSE_FUNC()
334 if (data->lastkey) { in PS_CLOSE_FUNC()
335 efree(data->lastkey); in PS_CLOSE_FUNC()
338 efree(data->basedir); in PS_CLOSE_FUNC()
339 efree(data); in PS_CLOSE_FUNC()
351 ps_files_open(data, key TSRMLS_CC); in PS_READ_FUNC()
352 if (data->fd < 0) { in PS_READ_FUNC()
356 if (fstat(data->fd, &sbuf)) { in PS_READ_FUNC()
360 data->st_size = *vallen = sbuf.st_size; in PS_READ_FUNC()
370 n = pread(data->fd, *val, sbuf.st_size, 0); in PS_READ_FUNC()
372 lseek(data->fd, 0, SEEK_SET); in PS_READ_FUNC()
373 n = read(data->fd, *val, sbuf.st_size); in PS_READ_FUNC()
394 ps_files_open(data, key TSRMLS_CC); in PS_WRITE_FUNC()
395 if (data->fd < 0) { in PS_WRITE_FUNC()
401 if (vallen < (int)data->st_size) { in PS_WRITE_FUNC()
402 ftruncate(data->fd, 0); in PS_WRITE_FUNC()
406 n = pwrite(data->fd, val, vallen, 0); in PS_WRITE_FUNC()
408 lseek(data->fd, 0, SEEK_SET); in PS_WRITE_FUNC()
409 n = write(data->fd, val, vallen); in PS_WRITE_FUNC()
429 if (!ps_files_path_create(buf, sizeof(buf), data, key)) { in PS_DESTROY_FUNC()
433 if (data->fd != -1) { in PS_DESTROY_FUNC()
434 ps_files_close(data); in PS_DESTROY_FUNC()
456 if (data->dirdepth == 0) { in PS_GC_FUNC()
457 *nrdels = ps_files_cleanup_dir(data->basedir, maxlifetime TSRMLS_CC); in PS_GC_FUNC()