-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathls.h
76 lines (62 loc) · 1.79 KB
/
ls.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/**
* Command to list computer files and directories.
* Copyright (C) 2024 Alexander (@alkuzin).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef _LS_H_
#define _LS_H_
#include <sys/stat.h>
#include <dirent.h>
#include <stdint.h>
typedef struct stat stat_t;
/* file structure */
typedef struct ls_file_s {
char filename[256];
char group[256];
char user[256];
char mode[12];
char date[16];
size_t nlink;
size_t size;
time_t mtime;
} ls_file_t;
/* ls structure */
typedef struct ls_s {
ls_file_t files[256];
char dirname[256];
struct dirent *dp;
size_t size;
DIR *dir;
uint8_t flags;
} ls_t;
/* ls flags -l -a -r -t -S */
#define LS_FLAG_LONG_LIST 0x01
#define LS_FLAG_ALL 0x02
#define LS_FLAG_REVERSE 0x04
#define LS_FLAG_TIME 0x08
#define LS_FLAG_SIZE 0x10
/* initialize ls struct */
void ls_init(ls_t *ls);
/* open directory */
void ls_opendir(ls_t *ls, const char *path);
/* read directory */
void ls_readdir(ls_t *ls);
/* print directory contents */
void ls_printdir(ls_t *ls);
/* close directory & free ls struct */
void ls_destroy(ls_t *ls);
/* show list of options */
void ls_help(void);
#endif /* _LS_H_ */