CS360 Exam #1 Struct and Procedure definitions
Stat
#include
#include
int stat(char *path, struct stat buf)
struct stat {
ino_t st_ino; /* the file serial number */
mode_t st_mode; /* file mode */
nlink_t st_nlink; /* number of hard links to the file */
uid_t st_uid; /* user ID of owner */
gid_t st_gid; /* group ID of owner */
off_t st_size; /* total size of file, in bytes */
time_t st_atime; /* file last access time */
time_t st_mtime; /* file last modify time */
time_t st_ctime; /* file last status change time */
};
Opendir, etc
DIR *opendir(char *dirname)
struct dirent *readdir(DIR *dirp)
int closedir(DIR *dirp)
struct dirent {
off_t d_off; /* offset of next disk dir entry */
unsigned long d_fileno; /* file (inode) number of entry */
unsigned short d_reclen; /* length of this record */
unsigned short d_namlen; /* length of string in d_name */
char d_name[255+1]; /* name (up to MAXNAMLEN + 1) */
};
Rb-trees
Rb_node make_rb(); /* Creates a new rb-tree */
Rb_node rb_insert(Rb_node tree, char *key, char *val);
Rb_node rb_find_key_n(Rb_node root, char *key, int *found);
#define rb_first(n) (n->c.list.flink)
#define rb_next(n) (n->c.list.flink)
#define rb_nil(t) (t)
#define rb_traverse(ptr, lst) \
for(ptr = rb_first(lst); ptr != rb_nil(lst); ptr = rb_next(ptr))
Fields
#define MAXLEN 1001
#define MAXFIELDS 1000
typedef struct inputstruct {
char *name; /* File name */
FILE *f; /* File descriptor */
int line; /* Line number */
char text1[MAXLEN]; /* The line */
char text2[MAXLEN]; /* Working -- contains fields */
int NF; /* Number of fields */
char *fields[MAXFIELDS]; /* Pointers to fields */
int file; /* 1 for file, 0 for popen */
} *IS;
extern IS new_inputstruct(/* FILENAME -- NULL for stdin */);
extern int get_line(/* IS */); /* returns NF, or -1 on EOF. Does not
close the file */