forked from bonsai/harakit
Merge branch 'rmlibfileis'
This commit is contained in:
commit
3249a83861
@ -61,8 +61,8 @@ false: src/false.rs build_dir
|
|||||||
intcmp: src/intcmp.c build_dir
|
intcmp: src/intcmp.c build_dir
|
||||||
$(CC) $(CFLAGS) -o build/bin/intcmp src/intcmp.c
|
$(CC) $(CFLAGS) -o build/bin/intcmp src/intcmp.c
|
||||||
|
|
||||||
scrut: src/scrut.c libfileis build_dir
|
scrut: src/scrut.c build_dir
|
||||||
$(CC) $(CFLAGS) -lfileis -o build/bin/scrut src/scrut.c
|
$(CC) $(CFLAGS) -o build/bin/scrut src/scrut.c
|
||||||
|
|
||||||
str: src/str.c build_dir
|
str: src/str.c build_dir
|
||||||
$(CC) $(CFLAGS) -o build/bin/str src/str.c
|
$(CC) $(CFLAGS) -o build/bin/str src/str.c
|
||||||
@ -73,7 +73,3 @@ strcmp: src/strcmp.c build_dir
|
|||||||
true: src/true.rs build_dir
|
true: src/true.rs build_dir
|
||||||
$(RUSTC) $(RUSTCFLAGS) -o build/bin/true src/true.rs
|
$(RUSTC) $(RUSTCFLAGS) -o build/bin/true src/true.rs
|
||||||
|
|
||||||
libfileis: src/libfileis.c src/libfileis.h build_dir
|
|
||||||
$(CC) $(CFLAGS) -c -fPIC -o build/o/libfileis.o src/libfileis.c
|
|
||||||
$(CC) -shared -o build/lib/libfileis.so build/o/libfileis.o
|
|
||||||
|
|
||||||
|
@ -1,63 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2023 DTB <trinity@trinity.moe>
|
|
||||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify it under
|
|
||||||
* the terms of the GNU Affero 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 Affero General Public License for more
|
|
||||||
* details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see https://www.gnu.org/licenses/.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "libfileis.h"
|
|
||||||
|
|
||||||
#include <unistd.h> /* access(3), F_OK, R_OK, W_OK, X_OK */
|
|
||||||
|
|
||||||
int f_executable(char *path){ return access(path, X_OK) == 0; } /* test -x */
|
|
||||||
int f_exists(char *path){ return access(path, F_OK) == 0; } /* test -e */
|
|
||||||
int f_readable(char *path){ return access(path, R_OK) == 0; } /* test -r */
|
|
||||||
int f_writeable(char *path){ return access(path, W_OK) == 0; } /* test -w */
|
|
||||||
|
|
||||||
#include <sys/stat.h> /* lstat(3), struct stat, S_ISBLK, S_ISCHR, S_ISDIR,
|
|
||||||
* S_ISFIFO, S_ISGID, S_ISREG, S_ISLNK, S_ISSOCK,
|
|
||||||
* S_ISUID, S_ISVTX */
|
|
||||||
|
|
||||||
static struct stat buf;
|
|
||||||
|
|
||||||
int f_blockspecial(char *path){ /* test -b */
|
|
||||||
return lstat(path, &buf) != -1 && S_ISBLK(buf.st_mode);
|
|
||||||
}
|
|
||||||
int f_charspecial(char *path){ /* test -c */
|
|
||||||
return lstat(path, &buf) != -1 && S_ISCHR(buf.st_mode);
|
|
||||||
}
|
|
||||||
int f_directory(char *path){ /* test -d */
|
|
||||||
return lstat(path, &buf) != -1 && S_ISDIR(buf.st_mode);
|
|
||||||
}
|
|
||||||
int f_fifospecial(char *path){ /* test -p */
|
|
||||||
return lstat(path, &buf) != -1 && S_ISFIFO(buf.st_mode);
|
|
||||||
}
|
|
||||||
int f_gid(char *path){ /* test -g */
|
|
||||||
return lstat(path, &buf) != -1 && (buf.st_mode & S_ISGID);
|
|
||||||
}
|
|
||||||
int f_regular(char *path){ /* test -f */
|
|
||||||
return lstat(path, &buf) != -1 && S_ISREG(buf.st_mode);
|
|
||||||
}
|
|
||||||
int f_socket(char *path){ /* test -S */
|
|
||||||
return lstat(path, &buf) != -1 && S_ISSOCK(buf.st_mode);
|
|
||||||
}
|
|
||||||
int f_sticky(char *path){ /* test -k */
|
|
||||||
return lstat(path, &buf) != -1 && (buf.st_mode & S_ISVTX);
|
|
||||||
}
|
|
||||||
int f_symlink(char *path){ /* test -h; test -L */
|
|
||||||
return lstat(path, &buf) != -1 && S_ISLNK(buf.st_mode);
|
|
||||||
}
|
|
||||||
int f_uid(char *path){ /* test -u */
|
|
||||||
return lstat(path, &buf) != -1 && (buf.st_mode & S_ISUID);
|
|
||||||
}
|
|
@ -1,62 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2023 DTB <trinity@trinity.moe>
|
|
||||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify it under
|
|
||||||
* the terms of the GNU Affero 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 Affero General Public License for more
|
|
||||||
* details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see https://www.gnu.org/licenses/.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* libfileis functions return true if the condition is true and false if the
|
|
||||||
* condition is false. Returned values are 0 or 1 only. */
|
|
||||||
|
|
||||||
/* True if file exists and is a block special file. */
|
|
||||||
int f_blockspecial(char *path);
|
|
||||||
|
|
||||||
/* True if file exists and is a character special file. */
|
|
||||||
int f_charspecial(char *path);
|
|
||||||
|
|
||||||
/* True if file exists and is a directory. */
|
|
||||||
int f_directory(char *path);
|
|
||||||
|
|
||||||
/* True if file exists and is executable. */
|
|
||||||
int f_executable(char *path);
|
|
||||||
|
|
||||||
/* True if file exists (regardless of type). */
|
|
||||||
int f_exists(char *path);
|
|
||||||
|
|
||||||
/* True if file exists and is a named pipe (FIFO). */
|
|
||||||
int f_fifospecial(char *path);
|
|
||||||
|
|
||||||
/* True if file exists and its set group ID flag is set. */
|
|
||||||
int f_gid(char *path);
|
|
||||||
|
|
||||||
/* True if file exists and is readable. */
|
|
||||||
int f_readable(char *path);
|
|
||||||
|
|
||||||
/* True if file exists and is a regular file. */
|
|
||||||
int f_regular(char *path);
|
|
||||||
|
|
||||||
/* True if file exists and is a socket. */
|
|
||||||
int f_socket(char *path);
|
|
||||||
|
|
||||||
/* True if file exists and its sticky bit is set. */
|
|
||||||
int f_sticky(char *path);
|
|
||||||
|
|
||||||
/* True if file exists and is a symbolic link. */
|
|
||||||
int f_symlink(char *path);
|
|
||||||
|
|
||||||
/* True if file exists and its set user ID flag is set. */
|
|
||||||
int f_uid(char *path);
|
|
||||||
|
|
||||||
/* True if file exists and is writeable. */
|
|
||||||
int f_writeable(char *path);
|
|
Loading…
Reference in New Issue
Block a user