Back to index

im-sdk  12.3.91
Classes | Functions | Variables
fop_file.c File Reference
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <stdarg.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <dirent.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <ulimit.h>
#include <utime.h>
#include <sys/time.h>
#include <sys/uio.h>
#include "fop.h"

Go to the source code of this file.

Classes

struct  fop_name_function_t
union  fop_data_t

Functions

static fop_data_tfop_open (fopc_t *fopc, const char *path, int oflag, mode_t mode)
static int fop_close (fopc_t *fopc, fop_data_t *data)
static fop_data_tfop_creat (fopc_t *fopc, const char *path, mode_t mode)
static size_t fop_read (fopc_t *fopc, fop_data_t *data, void *buf, size_t nbyte)
static size_t fop_write (fopc_t *fopc, fop_data_t *data, const void *buf, size_t nbyte)
static off_t fop_lseek (fopc_t *fopc, fop_data_t *data, off_t offset, int whence)
static int fop_stat (fopc_t *fopc, const char *path, struct stat *buf)
static int fop_lstat (fopc_t *fopc, const char *path, struct stat *buf)
static int fop_fstat (fopc_t *fopc, fop_data_t *data, struct stat *buf)
static int fop_symlink (fopc_t *fopc, const char *name1, const char *name2)
static int fop_readlink (fopc_t *fopc, const char *path, char *buf, size_t bufsiz)
static int fop_link (fopc_t *fopc, const char *existing, const char *new)
static int fop_unlink (fopc_t *fopc, const char *path)
static int fop_rename (fopc_t *fopc, const char *old, const char *new)
static int fop_fcntl (fopc_t *fopc, fop_data_t *data, int cmd,...)
static int fop_truncate (fopc_t *fopc, const char *path, off_t length)
static int fop_ftruncate (fopc_t *fopc, fop_data_t *data, off_t length)
static int fop_mkdir (fopc_t *fopc, const char *path, mode_t mode)
static int fop_rmdir (fopc_t *fopc, const char *path)
static fop_data_tfop_opendir (fopc_t *fopc, const char *dirname)
static struct dirent * fop_readdir (fopc_t *fopc, fop_data_t *data)
static int fop_closedir (fopc_t *fopc, fop_data_t *data)
static void fop_rewinddir (fopc_t *fopc, fop_data_t *data)
static void fop_seekdir (fopc_t *fopc, fop_data_t *data, long int loc)
static long int fop_telldir (fopc_t *fopc, fop_data_t *data)
static int fop_access (fopc_t *fopc, const char *path, int amode)
static int fop_chmod (fopc_t *fopc, const char *path, mode_t mode)
static int fop_fchmod (fopc_t *fopc, fop_data_t *data, mode_t mode)
static int fop_chown (fopc_t *fopc, const char *path, uid_t owner, gid_t group)
static int fop_fchown (fopc_t *fopc, fop_data_t *data, uid_t owner, gid_t group)
static int fop_utime (fopc_t *fopc, const char *path, const struct utimbuf *times)
static int fop_utimes (fopc_t *fopc, const char *path, const struct timeval *times)
void * fop_scheme_file_get_function (const char *name)

Variables

static fop_name_function_t fop_name_function_list []

Class Documentation

struct fop_name_function_t

Definition at line 87 of file fop.c.

Class Members
void * function
char * name
fop_func_type_t type
union fop_data_t

Definition at line 29 of file fop_file.c.

Class Members
DIR * dirp
int fd

Function Documentation

static int fop_access ( fopc_t fopc,
const char *  path,
int  amode 
) [static]

Definition at line 523 of file fop_file.c.

{
    return access(path, amode);
}
static int fop_chmod ( fopc_t fopc,
const char *  path,
mode_t  mode 
) [static]

Definition at line 534 of file fop_file.c.

{
    return chmod(path, mode);
}
static int fop_chown ( fopc_t fopc,
const char *  path,
uid_t  owner,
gid_t  group 
) [static]

Definition at line 561 of file fop_file.c.

{
    return chown(path, owner, group);
}
static int fop_close ( fopc_t fopc,
fop_data_t data 
) [static]

Definition at line 63 of file fop_file.c.

{
    int              fd;

    if (NULL == data) {
       errno = EBADF;
       return -1;
    }

    fd = data->fd;
    free(data);

    return close(fd);
}

Here is the call graph for this function:

static int fop_closedir ( fopc_t fopc,
fop_data_t data 
) [static]

Definition at line 455 of file fop_file.c.

{
    DIR *     dirp;

    if (NULL == data) {
       errno = EBADF;
       return -1;
    }

    dirp = data->dirp;
    free(data);

    return closedir(dirp);
}
static fop_data_t* fop_creat ( fopc_t fopc,
const char *  path,
mode_t  mode 
) [static]

Definition at line 83 of file fop_file.c.

{
    int                     fd;
    fop_data_t *     data;

    fd = creat(path, mode);
    if (0 <= fd) {
       data = (fop_data_t *)malloc(sizeof (fop_data_t));
       if (NULL == data) {
           close(fd);
           errno = EAGAIN;
           return NULL;
       }
       data->fd = fd;
       return data;
    } else {
       return NULL;
    }
}

Here is the call graph for this function:

static int fop_fchmod ( fopc_t fopc,
fop_data_t data,
mode_t  mode 
) [static]

Definition at line 545 of file fop_file.c.

{
    if (NULL == data) {
       errno = EBADF;
       return -1;
    }

    return fchmod(data->fd, mode);
}
static int fop_fchown ( fopc_t fopc,
fop_data_t data,
uid_t  owner,
gid_t  group 
) [static]

Definition at line 587 of file fop_file.c.

{
    if (NULL == data) {
       errno = EBADF;
       return -1;
    }

    return fchown(data->fd, owner, group);
}
static int fop_fcntl ( fopc_t fopc,
fop_data_t data,
int  cmd,
  ... 
) [static]

Definition at line 291 of file fop_file.c.

{
    va_list          ap;
    int                     arg_int;
    struct flock *   arg_flock;
#if defined(F_FREESP64) || defined(F_GETLK64) || \
    defined(F_SETLK64) || defined(F_SETLKW64)
    struct flock64 * arg_flock64;
#endif /* F_FREESP64 || F_GETLK64 || F_SETLK64 || F_SETLKW64 */
    int                     rv;

    if (NULL == data) {
       errno = EBADF;
       return -1;
    }

    va_start(ap, cmd);
    switch(cmd) {
    case F_DUPFD:
#if defined(F_DUP2FD)
    case F_DUP2FD:
#endif /* F_DUP2FD */
    case F_SETFD:
    case F_SETFL:
    case F_SETOWN:
       arg_int = va_arg(ap, int);
       rv = fcntl(data->fd, cmd, arg_int);
       break;
#if defined(F_FREESP)
    case F_FREESP:
#endif /* F_FREESP */
    case F_GETLK:
    case F_SETLK:
    case F_SETLKW:
       arg_flock = va_arg(ap, struct flock *);
       rv = fcntl(data->fd, cmd, arg_flock);
       break;
#if __WORDSIZE != 64 && !defined(__USE_FILE_OFFSET64)
       /* When __WORDSIZE is 64 or __USE_FILE_OFFSET64 is defined,
          F_*64 has similar number to F_*(non-64) */
#if defined(F_FREESP64)
    case F_FREESP64:
#endif /* F_FREESP64 */
#if defined(F_GETLK64)
    case F_GETLK64:
#endif /* F_GETLK64 */
#if defined(F_SETLK64)
    case F_SETLK64:
#endif /* F_SETLK64 */
#if defined(F_SETLKW64)
    case F_SETLKW64:
#endif /* F_SETLKW64 */

#if defined(F_FREESP64) || defined(F_GETLK64) || defined(F_SETLK64) || defined(F_SETLKW64)
       arg_flock64 = va_arg(ap, struct flock64 *);
       rv = fcntl(data->fd, cmd, arg_flock64);
       break;
#endif /* F_FREESP64 || F_GETLK64 || F_SETLK64 || F_SETLKW64 */
#endif
    default:
       rv = fcntl(data->fd, cmd, 0);
       break;
    }
    va_end(ap);

    return rv;
}
static int fop_fstat ( fopc_t fopc,
fop_data_t data,
struct stat *  buf 
) [static]

Definition at line 220 of file fop_file.c.

{
    if (NULL == data) {
       errno = EBADF;
       return -1;
    }

    return fstat(data->fd, buf);
}
static int fop_ftruncate ( fopc_t fopc,
fop_data_t data,
off_t  length 
) [static]

Definition at line 377 of file fop_file.c.

{
    if (NULL == data) {
       errno = EBADF;
       return -1;
    }

    return ftruncate(data->fd, length);
}
static int fop_link ( fopc_t fopc,
const char *  existing,
const char *  new 
) [static]

Definition at line 259 of file fop_file.c.

{
    return link(existing, new);
}
static off_t fop_lseek ( fopc_t fopc,
fop_data_t data,
off_t  offset,
int  whence 
) [static]

Definition at line 181 of file fop_file.c.

{
    if (NULL == data) {
       errno = EBADF;
       return -1;
    }

    return lseek(data->fd, offset, whence);
}
static int fop_lstat ( fopc_t fopc,
const char *  path,
struct stat *  buf 
) [static]

Definition at line 209 of file fop_file.c.

{
    return lstat(path, buf);
}
static int fop_mkdir ( fopc_t fopc,
const char *  path,
mode_t  mode 
) [static]

Definition at line 393 of file fop_file.c.

{
    return mkdir(path, mode);
}
static fop_data_t* fop_open ( fopc_t fopc,
const char *  path,
int  oflag,
mode_t  mode 
) [static]

Definition at line 36 of file fop_file.c.

{
    int                     fd;
    fop_data_t *     data;

    fd = open(path, oflag, mode);
    if (0 <= fd) {
       data = (fop_data_t *)malloc(sizeof (fop_data_t));
       if (NULL == data) {
           close(fd);
           errno = EAGAIN;
           return NULL;
       }
       data->fd = fd;
       return data;
    } else {
       return NULL;
    }
}

Here is the call graph for this function:

static fop_data_t* fop_opendir ( fopc_t fopc,
const char *  dirname 
) [static]

Definition at line 414 of file fop_file.c.

{
    DIR *            dirp;
    fop_data_t *     data;

    dirp = opendir(dirname);
    if (NULL != dirp) {
       data = (fop_data_t *)malloc(sizeof (fop_data_t));
       if (NULL == data) {
           closedir(dirp);
           errno = EAGAIN;
           return NULL;
       }
       data->dirp = dirp;
       return data;
    } else {
       return NULL;
    }

}
static size_t fop_read ( fopc_t fopc,
fop_data_t data,
void *  buf,
size_t  nbyte 
) [static]

Definition at line 109 of file fop_file.c.

{
    if (NULL == data) {
       errno = EBADF;
       return -1;
    }

    return read(data->fd, buf, nbyte);
}

Here is the call graph for this function:

static struct dirent* fop_readdir ( fopc_t fopc,
fop_data_t data 
) [static, read]

Definition at line 440 of file fop_file.c.

{
    if (NULL == data) {
       errno = EBADF;
       return NULL;
    }

    return readdir(data->dirp);
}
static int fop_readlink ( fopc_t fopc,
const char *  path,
char *  buf,
size_t  bufsiz 
) [static]

Definition at line 247 of file fop_file.c.

{
    return readlink(path, buf, bufsiz);
}
static int fop_rename ( fopc_t fopc,
const char *  old,
const char *  new 
) [static]

Definition at line 280 of file fop_file.c.

{
    return rename(old, new);
}
static void fop_rewinddir ( fopc_t fopc,
fop_data_t data 
) [static]

Definition at line 475 of file fop_file.c.

{
    if (NULL == data) {
       errno = EBADF;
       return;
    }

    rewinddir(data->dirp);
    return;
}
static int fop_rmdir ( fopc_t fopc,
const char *  path 
) [static]

Definition at line 404 of file fop_file.c.

{
    return rmdir(path);
}
void* fop_scheme_file_get_function ( const char *  name)

Definition at line 712 of file fop_file.c.

{
    fop_name_function_t *   nf;

    for (nf = fop_name_function_list; NULL != nf->name; nf += 1) {
       if (0 == strcmp(nf->name, name)) return nf->function;
    }

    return NULL;
}

Here is the caller graph for this function:

static void fop_seekdir ( fopc_t fopc,
fop_data_t data,
long int  loc 
) [static]

Definition at line 491 of file fop_file.c.

{
    if (NULL == data) {
       errno = EBADF;
       return;
    }

    seekdir(data->dirp, loc);
    return;
}
static int fop_stat ( fopc_t fopc,
const char *  path,
struct stat *  buf 
) [static]

Definition at line 198 of file fop_file.c.

{
    return stat(path, buf);
}
static int fop_symlink ( fopc_t fopc,
const char *  name1,
const char *  name2 
) [static]

Definition at line 236 of file fop_file.c.

{
    return symlink(name1, name2);
}
static long int fop_telldir ( fopc_t fopc,
fop_data_t data 
) [static]

Definition at line 508 of file fop_file.c.

{
    if (NULL == data) {
       errno = EBADF;
       return 0;
    }

    return telldir(data->dirp);
}
static int fop_truncate ( fopc_t fopc,
const char *  path,
off_t  length 
) [static]

Definition at line 366 of file fop_file.c.

{
    return truncate(path, length);
}
static int fop_unlink ( fopc_t fopc,
const char *  path 
) [static]

Definition at line 270 of file fop_file.c.

{
    return unlink(path);
}
static int fop_utime ( fopc_t fopc,
const char *  path,
const struct utimbuf *  times 
) [static]

Definition at line 635 of file fop_file.c.

{
    return utime(path, times);
}
static int fop_utimes ( fopc_t fopc,
const char *  path,
const struct timeval *  times 
) [static]

Definition at line 646 of file fop_file.c.

{
    return utimes(path, times);
}
static size_t fop_write ( fopc_t fopc,
fop_data_t data,
const void *  buf,
size_t  nbyte 
) [static]

Definition at line 145 of file fop_file.c.

{
    if (NULL == data) {
       errno = EBADF;
       return -1;
    }

    return write(data->fd, buf, nbyte);
}

Here is the call graph for this function:


Variable Documentation

Definition at line 656 of file fop_file.c.