w32tex
About: TeX Live provides a comprehensive TeX system including all the major TeX-related programs, macro packages, and fonts that are free software. Windows sources.
  Fossies Dox: w32tex-src.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

lfs.c File Reference
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <sys/stat.h>
#include <unistd.h>
#include <dirent.h>
#include <fcntl.h>
#include <sys/types.h>
#include <utime.h>
#include <sys/param.h>
#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>
#include "lfs.h"
Include dependency graph for lfs.c:

Go to the source code of this file.

Classes

struct  dir_data
 
struct  lfs_Lock
 
struct  _stat_members
 

Macros

#define _FILE_OFFSET_BITS   64 /* Linux, Solaris and HP-UX */
 
#define _LARGEFILE64_SOURCE
 
#define LFS_MAXPATHLEN   128
 
#define LFS_VERSION   "1.7.0"
 
#define LFS_LIBNAME   "lfs"
 
#define luaL_optlong   luaL_optinteger
 
#define new_lib(L, l)   (luaL_newlib(L, l))
 
#define DIR_METATABLE   "directory metatable"
 
#define LOCK_METATABLE   "lock metatable"
 
#define _O_TEXT   0
 
#define _O_BINARY   0
 
#define lfs_setmode(file, m)   ((void)file, (void)m, 0)
 
#define STAT_STRUCT   struct stat
 
#define STAT_FUNC   stat
 
#define LSTAT_FUNC   lstat
 
#define lfs_mkdir(path)
 

Typedefs

typedef struct dir_data dir_data
 
typedef struct lfs_Lock lfs_Lock
 
typedef void(* _push_function) (lua_State *L, struct stat *info)
 

Functions

static int pusherror (lua_State *L, const char *info)
 
static int pushresult (lua_State *L, int res, const char *info)
 
static int change_dir (lua_State *L)
 
static int get_dir (lua_State *L)
 
static FILEcheck_file (lua_State *L, int idx, const char *funcname)
 
static int _file_lock (lua_State *L, FILE *fh, const char *mode, const long start, long len, const char *funcname)
 
static int lfs_lock_dir (lua_State *L)
 
static int lfs_unlock_dir (lua_State *L)
 
static int lfs_g_setmode (lua_State *L, FILE *f, int arg)
 
static int lfs_f_setmode (lua_State *L)
 
static int file_lock (lua_State *L)
 
static int file_unlock (lua_State *L)
 
static int make_link (lua_State *L)
 
static int make_dir (lua_State *L)
 
static int remove_dir (lua_State *L)
 
static int dir_iter (lua_State *L)
 
static int dir_close (lua_State *L)
 
static int dir_iter_factory (lua_State *L)
 
static int dir_create_meta (lua_State *L)
 
static int lock_create_meta (lua_State *L)
 
static const char * mode2string (mode_t mode)
 
static int file_utime (lua_State *L)
 
static void push_st_mode (lua_State *L, struct stat *info)
 
static void push_st_dev (lua_State *L, struct stat *info)
 
static void push_st_ino (lua_State *L, struct stat *info)
 
static void push_st_nlink (lua_State *L, struct stat *info)
 
static void push_st_uid (lua_State *L, struct stat *info)
 
static void push_st_gid (lua_State *L, struct stat *info)
 
static void push_st_rdev (lua_State *L, struct stat *info)
 
static void push_st_atime (lua_State *L, struct stat *info)
 
static void push_st_mtime (lua_State *L, struct stat *info)
 
static void push_st_ctime (lua_State *L, struct stat *info)
 
static void push_st_size (lua_State *L, struct stat *info)
 
static void push_st_blocks (lua_State *L, struct stat *info)
 
static void push_st_blksize (lua_State *L, struct stat *info)
 
static const char * perm2string (mode_t mode)
 
static void push_st_perm (lua_State *L, struct stat *info)
 
static int _file_info_ (lua_State *L, int(*st)(const char *, struct stat *))
 
static int file_info (lua_State *L)
 
static int push_link_target (lua_State *L)
 
static int link_info (lua_State *L)
 
static void set_info (lua_State *L)
 
int luaopen_lfs (lua_State *L)
 

Variables

struct _stat_members members []
 
static const struct luaL_Reg fslib []
 

Macro Definition Documentation

◆ _FILE_OFFSET_BITS

#define _FILE_OFFSET_BITS   64 /* Linux, Solaris and HP-UX */

Definition at line 25 of file lfs.c.

◆ _LARGEFILE64_SOURCE

#define _LARGEFILE64_SOURCE

Definition at line 33 of file lfs.c.

◆ _O_BINARY

#define _O_BINARY   0

Definition at line 127 of file lfs.c.

◆ _O_TEXT

#define _O_TEXT   0

Definition at line 126 of file lfs.c.

◆ DIR_METATABLE

#define DIR_METATABLE   "directory metatable"

Definition at line 98 of file lfs.c.

◆ LFS_LIBNAME

#define LFS_LIBNAME   "lfs"

Definition at line 77 of file lfs.c.

◆ LFS_MAXPATHLEN

#define LFS_MAXPATHLEN   128

Definition at line 66 of file lfs.c.

◆ lfs_mkdir

#define lfs_mkdir (   path)
Value:
(mkdir((path), \
int mkdir(const char *, mode_t)
#define S_IXGRP
Definition: progname.c:63
#define S_IXOTH
Definition: progname.c:66
#define S_IXUSR
Definition: progname.c:59
#define S_IROTH
Definition: win32lib.h:155
#define S_IRGRP
Definition: win32lib.h:161
#define S_IRUSR
Definition: win32lib.h:149
#define S_IWUSR
Definition: win32lib.h:152
#define S_IWGRP
Definition: win32lib.h:164
Definition: tpic.c:45

Definition at line 137 of file lfs.c.

◆ lfs_setmode

#define lfs_setmode (   file,
  m 
)    ((void)file, (void)m, 0)

Definition at line 128 of file lfs.c.

◆ LFS_VERSION

#define LFS_VERSION   "1.7.0"

Definition at line 76 of file lfs.c.

◆ LOCK_METATABLE

#define LOCK_METATABLE   "lock metatable"

Definition at line 109 of file lfs.c.

◆ LSTAT_FUNC

#define LSTAT_FUNC   lstat

Definition at line 131 of file lfs.c.

◆ luaL_optlong

#define luaL_optlong   luaL_optinteger

Definition at line 82 of file lfs.c.

◆ new_lib

#define new_lib (   L,
 
)    (luaL_newlib(L, l))

Definition at line 88 of file lfs.c.

◆ STAT_FUNC

#define STAT_FUNC   stat

Definition at line 130 of file lfs.c.

◆ STAT_STRUCT

#define STAT_STRUCT   struct stat

Definition at line 129 of file lfs.c.

Typedef Documentation

◆ _push_function

typedef void(* _push_function) (lua_State *L, struct stat *info)

Definition at line 802 of file lfs.c.

◆ dir_data

typedef struct dir_data dir_data

◆ lfs_Lock

typedef struct lfs_Lock lfs_Lock

Function Documentation

◆ _file_info_()

◆ _file_lock()

static int _file_lock ( lua_State L,
FILE fh,
const char *  mode,
const long  start,
long  len,
const char *  funcname 
)
static

Definition at line 253 of file lfs.c.

References code, fc-lang::default, f, fcntl(), fileno, fseek, ftell, funcname, L, len, locking(), luaL_error(), mode, SEEK_END, SEEK_SET, and start.

Referenced by file_lock(), and file_unlock().

◆ change_dir()

static int change_dir ( lua_State L)
static

Definition at line 168 of file lfs.c.

References chdir, chdir_error, L, lua_pushboolean(), lua_pushfstring(), lua_pushnil(), and luaL_checkstring.

◆ check_file()

static FILE* check_file ( lua_State L,
int  idx,
const char *  funcname 
)
static

Definition at line 229 of file lfs.c.

References FILE, funcname, idx, L, luaL_checkudata(), luaL_error(), and NULL.

Referenced by file_lock(), file_unlock(), and lfs_f_setmode().

◆ dir_close()

static int dir_close ( lua_State L)
static

Definition at line 553 of file lfs.c.

References closedir(), d, L, and lua_touserdata().

Referenced by dir_create_meta().

◆ dir_create_meta()

static int dir_create_meta ( lua_State L)
static

◆ dir_iter()

static int dir_iter ( lua_State L)
static

◆ dir_iter_factory()

◆ file_info()

static int file_info ( lua_State L)
static

Definition at line 873 of file lfs.c.

References _file_info_(), L, and STAT_FUNC.

◆ file_lock()

◆ file_unlock()

static int file_unlock ( lua_State L)
static

◆ file_utime()

static int file_utime ( lua_State L)
static

◆ get_dir()

static int get_dir ( lua_State L)
static

◆ lfs_f_setmode()

static int lfs_f_setmode ( lua_State L)
static

Definition at line 397 of file lfs.c.

References check_file(), L, and lfs_g_setmode().

◆ lfs_g_setmode()

static int lfs_g_setmode ( lua_State L,
FILE f,
int  arg 
)
static

◆ lfs_lock_dir()

◆ lfs_unlock_dir()

static int lfs_unlock_dir ( lua_State L)
static

Definition at line 365 of file lfs.c.

References free, L, lock, LOCK_METATABLE, luaL_checkudata(), NULL, and unlink.

Referenced by lock_create_meta().

◆ link_info()

◆ lock_create_meta()

static int lock_create_meta ( lua_State L)
static

Definition at line 619 of file lfs.c.

References L, lfs_unlock_dir(), LOCK_METATABLE, lua_newtable, lua_pushcfunction, lua_setfield(), and luaL_newmetatable().

Referenced by luaopen_lfs().

◆ luaopen_lfs()

int luaopen_lfs ( lua_State L)

◆ make_dir()

static int make_dir ( lua_State L)
static

Definition at line 473 of file lfs.c.

References L, lfs_mkdir, luaL_checkstring, NULL, and pushresult().

◆ make_link()

static int make_link ( lua_State L)
static

Definition at line 451 of file lfs.c.

References errno, L, link, lua_pushinteger(), lua_toboolean(), luaL_checkstring, NULL, pusherror(), and pushresult().

◆ mode2string()

static const char* mode2string ( mode_t  mode)
static

Definition at line 664 of file lfs.c.

References mode, S_ISBLK, S_ISCHR, S_ISDIR, S_ISFIFO, and S_ISREG.

Referenced by push_st_mode().

◆ perm2string()

static const char* perm2string ( mode_t  mode)
static

Definition at line 780 of file lfs.c.

References i, mode, S_IRGRP, S_IROTH, S_IRUSR, S_IWGRP, S_IWOTH, S_IWUSR, S_IXGRP, S_IXOTH, and S_IXUSR.

Referenced by push_st_perm().

◆ push_link_target()

static int push_link_target ( lua_State L)
static

Definition at line 884 of file lfs.c.

References errno, free, L, lua_pushlstring(), luaL_checkstring, NULL, realloc, size, and target.

Referenced by link_info().

◆ push_st_atime()

static void push_st_atime ( lua_State L,
struct stat info 
)
static

Definition at line 736 of file lfs.c.

References info, L, and lua_pushinteger().

◆ push_st_blksize()

static void push_st_blksize ( lua_State L,
struct stat info 
)
static

Definition at line 757 of file lfs.c.

References info, L, and lua_pushinteger().

◆ push_st_blocks()

static void push_st_blocks ( lua_State L,
struct stat info 
)
static

Definition at line 753 of file lfs.c.

References info, L, and lua_pushinteger().

◆ push_st_ctime()

static void push_st_ctime ( lua_State L,
struct stat info 
)
static

Definition at line 744 of file lfs.c.

References info, L, and lua_pushinteger().

◆ push_st_dev()

static void push_st_dev ( lua_State L,
struct stat info 
)
static

Definition at line 712 of file lfs.c.

References info, L, and lua_pushinteger().

◆ push_st_gid()

static void push_st_gid ( lua_State L,
struct stat info 
)
static

Definition at line 728 of file lfs.c.

References info, L, and lua_pushinteger().

◆ push_st_ino()

static void push_st_ino ( lua_State L,
struct stat info 
)
static

Definition at line 716 of file lfs.c.

References info, L, and lua_pushinteger().

◆ push_st_mode()

static void push_st_mode ( lua_State L,
struct stat info 
)
static

Definition at line 708 of file lfs.c.

References info, L, lua_pushstring(), and mode2string().

◆ push_st_mtime()

static void push_st_mtime ( lua_State L,
struct stat info 
)
static

Definition at line 740 of file lfs.c.

References info, L, and lua_pushinteger().

◆ push_st_nlink()

static void push_st_nlink ( lua_State L,
struct stat info 
)
static

Definition at line 720 of file lfs.c.

References info, L, and lua_pushinteger().

◆ push_st_perm()

static void push_st_perm ( lua_State L,
struct stat info 
)
static

Definition at line 798 of file lfs.c.

References info, L, lua_pushstring(), and perm2string().

◆ push_st_rdev()

static void push_st_rdev ( lua_State L,
struct stat info 
)
static

Definition at line 732 of file lfs.c.

References info, L, and lua_pushinteger().

◆ push_st_size()

static void push_st_size ( lua_State L,
struct stat info 
)
static

Definition at line 748 of file lfs.c.

References info, L, and lua_pushinteger().

◆ push_st_uid()

static void push_st_uid ( lua_State L,
struct stat info 
)
static

Definition at line 724 of file lfs.c.

References info, L, and lua_pushinteger().

◆ pusherror()

static int pusherror ( lua_State L,
const char *  info 
)
static

◆ pushresult()

static int pushresult ( lua_State L,
int  res,
const char *  info 
)
static

Definition at line 155 of file lfs.c.

References info, L, lua_pushboolean(), and pusherror().

Referenced by file_utime(), make_dir(), make_link(), and remove_dir().

◆ remove_dir()

static int remove_dir ( lua_State L)
static

Definition at line 483 of file lfs.c.

References L, luaL_checkstring, NULL, pushresult(), and rmdir.

◆ set_info()

static void set_info ( lua_State L)
static

Definition at line 936 of file lfs.c.

Referenced by luaopen_lfs().

Variable Documentation

◆ fslib

const struct luaL_Reg fslib[]
static
Initial value:
= {
{"attributes", file_info},
{"chdir", change_dir},
{"currentdir", get_dir},
{"dir", dir_iter_factory},
{"link", make_link},
{"lock", file_lock},
{"mkdir", make_dir},
{"rmdir", remove_dir},
{"symlinkattributes", link_info},
{"setmode", lfs_f_setmode},
{"touch", file_utime},
{"unlock", file_unlock},
{"lock_dir", lfs_lock_dir},
{ 0 , 0 },
}
static int remove_dir(lua_State *L)
Definition: lfs.c:483
static int lfs_f_setmode(lua_State *L)
Definition: lfs.c:397
static int file_lock(lua_State *L)
Definition: lfs.c:408
static int make_link(lua_State *L)
Definition: lfs.c:451
static int change_dir(lua_State *L)
Definition: lfs.c:168
static int file_utime(lua_State *L)
Definition: lfs.c:691
static int file_info(lua_State *L)
Definition: lfs.c:873
static int link_info(lua_State *L)
Definition: lfs.c:916
static int lfs_lock_dir(lua_State *L)
Definition: lfs.c:344
static int get_dir(lua_State *L)
Definition: lfs.c:190
static int dir_iter_factory(lua_State *L)
Definition: lfs.c:572
static int file_unlock(lua_State *L)
Definition: lfs.c:430
static int make_dir(lua_State *L)
Definition: lfs.c:473

Definition at line 936 of file lfs.c.

Referenced by luaopen_lfs().

◆ members

struct _stat_members members[]
Initial value:
= {
{ "mode", push_st_mode },
{ "dev", push_st_dev },
{ "ino", push_st_ino },
{ "nlink", push_st_nlink },
{ "uid", push_st_uid },
{ "gid", push_st_gid },
{ "rdev", push_st_rdev },
{ "access", push_st_atime },
{ "modification", push_st_mtime },
{ "change", push_st_ctime },
{ "size", push_st_size },
{ "permissions", push_st_perm },
{ "blocks", push_st_blocks },
{ "blksize", push_st_blksize },
{ 0 , 0 }
}
static void push_st_blksize(lua_State *L, struct stat *info)
Definition: lfs.c:757
static void push_st_perm(lua_State *L, struct stat *info)
Definition: lfs.c:798
static void push_st_rdev(lua_State *L, struct stat *info)
Definition: lfs.c:732
static void push_st_ctime(lua_State *L, struct stat *info)
Definition: lfs.c:744
static void push_st_atime(lua_State *L, struct stat *info)
Definition: lfs.c:736
static void push_st_nlink(lua_State *L, struct stat *info)
Definition: lfs.c:720
static void push_st_uid(lua_State *L, struct stat *info)
Definition: lfs.c:724
static void push_st_gid(lua_State *L, struct stat *info)
Definition: lfs.c:728
static void push_st_blocks(lua_State *L, struct stat *info)
Definition: lfs.c:753
static void push_st_size(lua_State *L, struct stat *info)
Definition: lfs.c:748
static void push_st_mtime(lua_State *L, struct stat *info)
Definition: lfs.c:740
static void push_st_mode(lua_State *L, struct stat *info)
Definition: lfs.c:708
static void push_st_dev(lua_State *L, struct stat *info)
Definition: lfs.c:712
static void push_st_ino(lua_State *L, struct stat *info)
Definition: lfs.c:716

Definition at line 802 of file lfs.c.

Referenced by _file_info_(), XeTeXFontMgr_Mac::addFamilyToCaches(), XeTeXFontMgr_Mac::addFontAndSiblingsToCaches(), make_struct(), make_struct_define_accessors(), mrb_struct_aset_sym(), mrb_struct_s_members_m(), mrb_struct_to_h(), num_members(), struct_aref_sym(), struct_members(), and struct_s_members().