Main Page | Modules | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

File I/O Handling Functions
[Brought To You By APR]


Modules

group  File Seek Flags
group  File Permissions flags
group  File Lock Types
group  File Open Flags/Routines

Data Structures

struct  switch_array_header_t

Typedefs

typedef apr_file_t switch_file_t
typedef int32_t switch_fileperms_t
typedef int switch_seek_where_t
typedef switch_dir switch_dir_t
typedef switch_array_header_t switch_array_header_t

Functions

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)
switch_status_t switch_file_seek (switch_file_t *thefile, switch_seek_where_t where, int64_t *offset)
switch_status_t switch_file_copy (const char *from_path, const char *to_path, switch_fileperms_t perms, switch_memory_pool_t *pool)
switch_status_t switch_file_close (switch_file_t *thefile)
switch_status_t switch_file_lock (switch_file_t *thefile, int type)
switch_status_t switch_file_remove (const char *path, switch_memory_pool_t *pool)
switch_status_t switch_file_rename (const char *from_path, const char *to_path, switch_memory_pool_t *pool)
switch_status_t switch_file_read (switch_file_t *thefile, void *buf, switch_size_t *nbytes)
switch_status_t switch_file_write (switch_file_t *thefile, const void *buf, switch_size_t *nbytes)
int switch_file_printf (switch_file_t *thefile, const char *format,...)
switch_status_t switch_file_mktemp (switch_file_t **thefile, char *templ, int32_t flags, switch_memory_pool_t *pool)
switch_size_t switch_file_get_size (switch_file_t *thefile)
switch_status_t switch_file_exists (const char *filename, switch_memory_pool_t *pool)
switch_status_t switch_directory_exists (const char *dirname, switch_memory_pool_t *pool)
switch_status_t switch_dir_make (const char *path, switch_fileperms_t perm, switch_memory_pool_t *pool)
switch_status_t switch_dir_make_recursive (const char *path, switch_fileperms_t perm, switch_memory_pool_t *pool)
switch_status_t switch_dir_open (switch_dir_t **new_dir, const char *dirname, switch_memory_pool_t *pool)
switch_status_t switch_dir_close (switch_dir_t *thedir)
const char * switch_dir_next_file (switch_dir_t *thedir, char *buf, switch_size_t len)


Typedef Documentation

typedef struct switch_array_header_t switch_array_header_t
 

typedef struct switch_dir switch_dir_t
 

typedef struct apr_file_t switch_file_t
 

Structure for referencing files.

typedef int32_t switch_fileperms_t
 

typedef int switch_seek_where_t
 


Function Documentation

switch_status_t switch_dir_close switch_dir_t thedir  ) 
 

00462 {
00463         switch_status_t status = apr_dir_close(thedir->dir_handle);
00464 
00465         free(thedir);
00466         return status;
00467 }

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.

Parameters:
path the path for the directory to be created. (use / on all systems)
perm Permissions for the new direcoty.
pool the pool to use.
00426 {
00427         return apr_dir_make(path, perm, pool);
00428 }

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.

Parameters:
path the path for the directory to be created. (use / on all systems)
perm Permissions for the new direcoty.
pool the pool to use.
00431 {
00432         return apr_dir_make_recursive(path, perm, pool);
00433 }

const char* switch_dir_next_file switch_dir_t thedir,
char *  buf,
switch_size_t  len
 

00470 {
00471         const char *fname = NULL;
00472         apr_int32_t finfo_flags = APR_FINFO_DIRENT | APR_FINFO_TYPE | APR_FINFO_NAME;
00473         const char *name;
00474 
00475         while (apr_dir_read(&(thedir->finfo), finfo_flags, thedir->dir_handle) == SWITCH_STATUS_SUCCESS) {
00476 
00477                 if (thedir->finfo.filetype != APR_REG) {
00478                         continue;
00479                 }
00480 
00481                 if (!(name = thedir->finfo.fname)) {
00482                         name = thedir->finfo.name;
00483                 }
00484 
00485                 if (!name) {
00486                         continue;
00487                 }
00488 
00489                 if (name) {
00490                         switch_copy_string(buf, name, len);
00491                         fname = buf;
00492                         break;
00493                 } else {
00494                         continue;
00495                 }
00496         }
00497         return fname;
00498 }

Here is the call graph for this function:

switch_status_t switch_dir_open switch_dir_t **  new_dir,
const char *  dirname,
switch_memory_pool_t pool
 

00441 {
00442         switch_status_t status;
00443         switch_dir_t *dir = malloc(sizeof(*dir));
00444 
00445         if (!dir) {
00446                 *new_dir = NULL;
00447                 return SWITCH_STATUS_FALSE;
00448         }
00449 
00450         memset(dir, 0, sizeof(*dir));
00451         if ((status = apr_dir_open(&(dir->dir_handle), dirname, pool)) == APR_SUCCESS) {
00452                 *new_dir = dir;
00453         } else {
00454                 free(dir);
00455                 *new_dir = NULL;
00456         }
00457 
00458         return status;
00459 }

switch_status_t switch_directory_exists const char *  dirname,
switch_memory_pool_t pool
 

00379 {
00380         apr_dir_t *dir_handle;
00381         switch_memory_pool_t *our_pool = NULL;
00382         switch_status_t status;
00383 
00384         if (!pool) {
00385                 switch_core_new_memory_pool(&our_pool);
00386                 pool = our_pool;
00387         }
00388 
00389         if ((status = apr_dir_open(&dir_handle, dirname, pool)) == APR_SUCCESS) {
00390                 apr_dir_close(dir_handle);
00391         }
00392 
00393         if (our_pool) {
00394                 switch_core_destroy_memory_pool(&our_pool);
00395         }
00396 
00397         return status;
00398 }

switch_status_t switch_file_close switch_file_t thefile  ) 
 

Close the specified file.

Parameters:
thefile The file descriptor to close.
00328 {
00329         return apr_file_close(thefile);
00330 }

switch_status_t switch_file_copy const char *  from_path,
const char *  to_path,
switch_fileperms_t  perms,
switch_memory_pool_t pool
 

00322 {
00323         return apr_file_copy(from_path, to_path, perms, pool);
00324 }

switch_status_t switch_file_exists const char *  filename,
switch_memory_pool_t pool
 

00401 {
00402         int32_t wanted = APR_FINFO_TYPE;
00403         switch_memory_pool_t *our_pool = NULL;
00404         switch_status_t status = SWITCH_STATUS_FALSE;
00405         apr_finfo_t info = { 0 };
00406 
00407         if (!pool) {
00408                 switch_core_new_memory_pool(&our_pool);
00409         }
00410 
00411         if (filename) {
00412                 apr_stat(&info, filename, wanted, pool ? pool : our_pool);
00413                 if (info.filetype != APR_NOFILE) {
00414                         status = SWITCH_STATUS_SUCCESS;
00415                 }
00416         }
00417 
00418         if (our_pool) {
00419                 switch_core_destroy_memory_pool(&our_pool);
00420         }
00421 
00422         return status;
00423 }

switch_size_t switch_file_get_size switch_file_t thefile  ) 
 

00373 {
00374         struct apr_finfo_t finfo;
00375         return apr_file_info_get(&finfo, APR_FINFO_SIZE, thefile) == SWITCH_STATUS_SUCCESS ? (switch_size_t) finfo.size : 0;
00376 }

switch_status_t switch_file_lock switch_file_t thefile,
int  type
 

00333 {
00334         return apr_file_lock(thefile, type);
00335 }

switch_status_t switch_file_mktemp switch_file_t **  thefile,
char *  templ,
int32_t  flags,
switch_memory_pool_t pool
 

00368 {
00369         return apr_file_mktemp(thefile, templ, flags, pool);
00370 }

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.

Parameters:
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.
Remarks:
If perm is SWITCH_FPROT_OS_DEFAULT and the file is being created, appropriate default permissions will be used.
00305 {
00306         return apr_file_open(newf, fname, flag, perm, pool);
00307 }

int switch_file_printf switch_file_t thefile,
const char *  format,
  ...
 

00358 {
00359         va_list ap;
00360         int ret;
00361         va_start(ap, format);
00362         ret = apr_file_printf(thefile, format, ap);
00363         va_end(ap);
00364         return ret;
00365 }

switch_status_t switch_file_read switch_file_t thefile,
void *  buf,
switch_size_t nbytes
 

Read data from the specified file.

Parameters:
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.
Remarks:
apr_file_read will read up to the specified number of bytes, but never more. If there isn't enough data to fill that number of bytes, all of the available data is read. The third argument is modified to reflect the number of bytes read. If a char was put back into the stream via ungetc, it will be the first character returned.

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.

00348 {
00349         return apr_file_read(thefile, buf, nbytes);
00350 }

switch_status_t switch_file_remove const char *  path,
switch_memory_pool_t pool
 

Delete the specified file.

Parameters:
path The full path to the file (using / on all systems)
pool The pool to use.
Remarks:
If the file is open, it won't be removed until all instances are closed.
00343 {
00344         return apr_file_remove(path, pool);
00345 }

switch_status_t switch_file_rename const char *  from_path,
const char *  to_path,
switch_memory_pool_t pool
 

00338 {
00339         return apr_file_rename(from_path, to_path, pool);
00340 }

switch_status_t switch_file_seek switch_file_t thefile,
switch_seek_where_t  where,
int64_t *  offset
 

00310 {
00311         apr_status_t rv;
00312         apr_off_t off = (apr_off_t) (*offset);
00313         rv = apr_file_seek(thefile, where, &off);
00314         *offset = (int64_t) off;
00315         return rv;
00316 }

switch_status_t switch_file_write switch_file_t thefile,
const void *  buf,
switch_size_t nbytes
 

Write data to the specified file.

Parameters:
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.
Remarks:
apr_file_write will write up to the specified number of bytes, but never more. If the OS cannot write that many bytes, it will write as many as it can. The third argument is modified to reflect 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.

00353 {
00354         return apr_file_write(thefile, buf, nbytes);
00355 }


Generated on Fri Oct 10 11:24:23 2008 for FreeSWITCH by  doxygen 1.3.9.1