Collaboration diagram for File I/O Handling Functions:
| typedef struct switch_array_header_t switch_array_header_t |
Definition at line 963 of file switch_apr.h.
| typedef struct switch_dir switch_dir_t |
Definition at line 949 of file switch_apr.h.
| typedef struct apr_file_t switch_file_t |
Structure for referencing files.
Definition at line 732 of file switch_apr.h.
| typedef int32_t switch_fileperms_t |
Definition at line 734 of file switch_apr.h.
| typedef int switch_seek_where_t |
Definition at line 735 of file switch_apr.h.
| switch_status_t switch_dir_close | ( | switch_dir_t * | thedir | ) |
Definition at line 576 of file switch_apr.c.
Referenced by switch_loadable_module_enumerate_available().
00577 { 00578 switch_status_t status = apr_dir_close(thedir->dir_handle); 00579 00580 free(thedir); 00581 return status; 00582 }
| switch_status_t switch_dir_make | ( | const char * | path, | |
| switch_fileperms_t | perm, | |||
| switch_memory_pool_t * | pool | |||
| ) |
Create a new directory on the file system.
| path | the path for the directory to be created. (use / on all systems) | |
| perm | Permissions for the new direcoty. | |
| pool | the pool to use. |
Definition at line 540 of file switch_apr.c.
00541 { 00542 return apr_dir_make(path, perm, pool); 00543 }
| switch_status_t switch_dir_make_recursive | ( | const char * | path, | |
| switch_fileperms_t | perm, | |||
| switch_memory_pool_t * | pool | |||
| ) |
Creates a new directory on the file system, but behaves like 'mkdir -p'. Creates intermediate directories as required. No error will be reported if PATH already exists.
| path | the path for the directory to be created. (use / on all systems) | |
| perm | Permissions for the new direcoty. | |
| pool | the pool to use. |
Definition at line 545 of file switch_apr.c.
Referenced by main(), switch_core_init(), and switch_ivr_record_session().
00546 { 00547 return apr_dir_make_recursive(path, perm, pool); 00548 }
| const char* switch_dir_next_file | ( | switch_dir_t * | thedir, | |
| char * | buf, | |||
| switch_size_t | len | |||
| ) |
Definition at line 584 of file switch_apr.c.
References switch_copy_string(), and SWITCH_STATUS_SUCCESS.
Referenced by switch_loadable_module_enumerate_available().
00585 { 00586 const char *fname = NULL; 00587 apr_int32_t finfo_flags = APR_FINFO_DIRENT | APR_FINFO_TYPE | APR_FINFO_NAME; 00588 const char *name; 00589 00590 while (apr_dir_read(&(thedir->finfo), finfo_flags, thedir->dir_handle) == SWITCH_STATUS_SUCCESS) { 00591 00592 if (thedir->finfo.filetype != APR_REG && thedir->finfo.filetype != APR_LNK) { 00593 continue; 00594 } 00595 00596 if (!(name = thedir->finfo.fname)) { 00597 name = thedir->finfo.name; 00598 } 00599 00600 if (!name) { 00601 continue; 00602 } 00603 00604 if (name) { 00605 switch_copy_string(buf, name, len); 00606 fname = buf; 00607 break; 00608 } else { 00609 continue; 00610 } 00611 } 00612 return fname; 00613 }
| switch_status_t switch_dir_open | ( | switch_dir_t ** | new_dir, | |
| const char * | dirname, | |||
| switch_memory_pool_t * | pool | |||
| ) |
Definition at line 555 of file switch_apr.c.
References SWITCH_STATUS_FALSE.
Referenced by switch_loadable_module_enumerate_available().
00556 { 00557 switch_status_t status; 00558 switch_dir_t *dir = malloc(sizeof(*dir)); 00559 00560 if (!dir) { 00561 *new_dir = NULL; 00562 return SWITCH_STATUS_FALSE; 00563 } 00564 00565 memset(dir, 0, sizeof(*dir)); 00566 if ((status = apr_dir_open(&(dir->dir_handle), dirname, pool)) == APR_SUCCESS) { 00567 *new_dir = dir; 00568 } else { 00569 free(dir); 00570 *new_dir = NULL; 00571 } 00572 00573 return status; 00574 }
| switch_status_t switch_directory_exists | ( | const char * | dirname, | |
| switch_memory_pool_t * | pool | |||
| ) |
Definition at line 491 of file switch_apr.c.
References switch_core_destroy_memory_pool, and switch_core_new_memory_pool.
00492 { 00493 apr_dir_t *dir_handle; 00494 switch_memory_pool_t *our_pool = NULL; 00495 switch_status_t status; 00496 00497 if (!pool) { 00498 switch_core_new_memory_pool(&our_pool); 00499 pool = our_pool; 00500 } 00501 00502 if ((status = apr_dir_open(&dir_handle, dirname, pool)) == APR_SUCCESS) { 00503 apr_dir_close(dir_handle); 00504 } 00505 00506 if (our_pool) { 00507 switch_core_destroy_memory_pool(&our_pool); 00508 } 00509 00510 return status; 00511 }
| switch_status_t switch_file_close | ( | switch_file_t * | thefile | ) |
Close the specified file.
| thefile | The file descriptor to close. |
Definition at line 426 of file switch_apr.c.
Referenced by main().
| switch_status_t switch_file_copy | ( | const char * | from_path, | |
| const char * | to_path, | |||
| switch_fileperms_t | perms, | |||
| switch_memory_pool_t * | pool | |||
| ) |
Definition at line 420 of file switch_apr.c.
00421 { 00422 return apr_file_copy(from_path, to_path, perms, pool); 00423 }
| switch_status_t switch_file_exists | ( | const char * | filename, | |
| switch_memory_pool_t * | pool | |||
| ) |
Definition at line 513 of file switch_apr.c.
References switch_core_destroy_memory_pool, switch_core_new_memory_pool, SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, and zstr.
Referenced by switch_core_perform_file_open().
00514 { 00515 int32_t wanted = APR_FINFO_TYPE; 00516 switch_memory_pool_t *our_pool = NULL; 00517 switch_status_t status = SWITCH_STATUS_FALSE; 00518 apr_finfo_t info = { 0 }; 00519 00520 if (zstr(filename)) { 00521 return status; 00522 } 00523 00524 if (!pool) { 00525 switch_core_new_memory_pool(&our_pool); 00526 } 00527 00528 apr_stat(&info, filename, wanted, pool ? pool : our_pool); 00529 if (info.filetype != APR_NOFILE) { 00530 status = SWITCH_STATUS_SUCCESS; 00531 } 00532 00533 if (our_pool) { 00534 switch_core_destroy_memory_pool(&our_pool); 00535 } 00536 00537 return status; 00538 }
| switch_size_t switch_file_get_size | ( | switch_file_t * | thefile | ) |
Definition at line 485 of file switch_apr.c.
References SWITCH_STATUS_SUCCESS.
00486 { 00487 struct apr_finfo_t finfo; 00488 return apr_file_info_get(&finfo, APR_FINFO_SIZE, thefile) == SWITCH_STATUS_SUCCESS ? (switch_size_t) finfo.size : 0; 00489 }
| switch_status_t switch_file_lock | ( | switch_file_t * | thefile, | |
| int | type | |||
| ) |
| switch_status_t switch_file_mktemp | ( | switch_file_t ** | thefile, | |
| char * | templ, | |||
| int32_t | flags, | |||
| switch_memory_pool_t * | pool | |||
| ) |
Definition at line 480 of file switch_apr.c.
00481 { 00482 return apr_file_mktemp(thefile, templ, flags, pool); 00483 }
| switch_status_t switch_file_open | ( | switch_file_t ** | newf, | |
| const char * | fname, | |||
| int32_t | flag, | |||
| switch_fileperms_t | perm, | |||
| switch_memory_pool_t * | pool | |||
| ) |
Open the specified file.
| newf | The opened file descriptor. | |
| fname | The full path to the file (using / on all systems) | |
| flag | Or'ed value of:
SWITCH_FOPEN_READ open for reading
SWITCH_FOPEN_WRITE open for writing
SWITCH_FOPEN_CREATE create the file if not there
SWITCH_FOPEN_APPEND file ptr is set to end prior to all writes
SWITCH_FOPEN_TRUNCATE set length to zero if file exists
SWITCH_FOPEN_BINARY not a text file (This flag is ignored on
UNIX because it has no meaning)
SWITCH_FOPEN_BUFFERED buffer the data. Default is non-buffered
SWITCH_FOPEN_EXCL return error if APR_CREATE and file exists
SWITCH_FOPEN_DELONCLOSE delete the file after closing.
SWITCH_FOPEN_XTHREAD Platform dependent tag to open the file
for use across multiple threads
SWITCH_FOPEN_SHARELOCK Platform dependent support for higher
level locked read/write access to support
writes across process/machines
SWITCH_FOPEN_NOCLEANUP Do not register a cleanup with the pool
passed in on the pool argument (see below).
The apr_os_file_t handle in apr_file_t will not
be closed when the pool is destroyed.
SWITCH_FOPEN_SENDFILE_ENABLED Open with appropriate platform semantics
for sendfile operations. Advisory only,
apr_socket_sendfile does not check this flag.
| |
| perm | Access permissions for file. | |
| pool | The pool to use. |
Definition at line 405 of file switch_apr.c.
Referenced by main().
00407 { 00408 return apr_file_open(newf, fname, flag, perm, pool); 00409 }
| int switch_file_printf | ( | switch_file_t * | thefile, | |
| const char * | format, | |||
| ... | ||||
| ) |
Definition at line 461 of file switch_apr.c.
References switch_file_write(), and switch_vasprintf().
00462 { 00463 va_list ap; 00464 int ret; 00465 char *data; 00466 00467 va_start(ap, format); 00468 00469 if ((ret = switch_vasprintf(&data, format, ap)) != -1) { 00470 switch_size_t bytes = strlen(data); 00471 switch_file_write(thefile, data, &bytes); 00472 free(data); 00473 } 00474 00475 va_end(ap); 00476 00477 return ret; 00478 }
| switch_status_t switch_file_read | ( | switch_file_t * | thefile, | |
| void * | buf, | |||
| switch_size_t * | nbytes | |||
| ) |
Read data from the specified file.
| thefile | The file descriptor to read from. | |
| buf | The buffer to store the data to. | |
| nbytes | On entry, the number of bytes to read; on exit, the number of bytes read. |
It is not possible for both bytes to be read and an APR_EOF or other error to be returned. APR_EINTR is never returned.
Definition at line 451 of file switch_apr.c.
Referenced by main().
00452 { 00453 return apr_file_read(thefile, buf, nbytes); 00454 }
| switch_status_t switch_file_remove | ( | const char * | path, | |
| switch_memory_pool_t * | pool | |||
| ) |
Delete the specified file.
| path | The full path to the file (using / on all systems) | |
| pool | The pool to use. |
Definition at line 446 of file switch_apr.c.
Referenced by record_callback().
00447 { 00448 return apr_file_remove(path, pool); 00449 }
| switch_status_t switch_file_rename | ( | const char * | from_path, | |
| const char * | to_path, | |||
| switch_memory_pool_t * | pool | |||
| ) |
Definition at line 441 of file switch_apr.c.
Referenced by switch_ivr_insert_file().
00442 { 00443 return apr_file_rename(from_path, to_path, pool); 00444 }
| switch_status_t switch_file_seek | ( | switch_file_t * | thefile, | |
| switch_seek_where_t | where, | |||
| int64_t * | offset | |||
| ) |
Definition at line 411 of file switch_apr.c.
00412 { 00413 apr_status_t rv; 00414 apr_off_t off = (apr_off_t) (*offset); 00415 rv = apr_file_seek(thefile, where, &off); 00416 *offset = (int64_t) off; 00417 return rv; 00418 }
| switch_status_t switch_file_trunc | ( | switch_file_t * | thefile, | |
| int64_t | offset | |||
| ) |
| switch_status_t switch_file_write | ( | switch_file_t * | thefile, | |
| const void * | buf, | |||
| switch_size_t * | nbytes | |||
| ) |
Write data to the specified file.
| thefile | The file descriptor to write to. | |
| buf | The buffer which contains the data. | |
| nbytes | On entry, the number of bytes to write; on exit, the number of bytes written. |
It is possible for both bytes to be written and an error to be returned. APR_EINTR is never returned.
Definition at line 456 of file switch_apr.c.
Referenced by main(), and switch_file_printf().
00457 { 00458 return apr_file_write(thefile, buf, nbytes); 00459 }
1.4.7