mirror of
https://github.com/jarun/nnn.git
synced 2024-12-01 02:49:44 +00:00
Use memccpy
This commit is contained in:
parent
315132b363
commit
35c3497364
2
Makefile
2
Makefile
|
@ -66,7 +66,7 @@ else
|
||||||
LDLIBS_CURSES ?= -lncurses
|
LDLIBS_CURSES ?= -lncurses
|
||||||
endif
|
endif
|
||||||
|
|
||||||
CFLAGS += -Wall -Wextra
|
CFLAGS += -std=c11 -Wall -Wextra
|
||||||
CFLAGS += $(CFLAGS_OPTIMIZATION)
|
CFLAGS += $(CFLAGS_OPTIMIZATION)
|
||||||
CFLAGS += $(CFLAGS_CURSES)
|
CFLAGS += $(CFLAGS_CURSES)
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ It runs smoothly on the Pi, [Termux](https://www.youtube.com/watch?v=AbaauM7gUJw
|
||||||
10. Configure the middle mouse click to do anything
|
10. Configure the middle mouse click to do anything
|
||||||
11. Fuzzy search subtree and open the dir of a file
|
11. Fuzzy search subtree and open the dir of a file
|
||||||
12. Load four dirs with custom settings at once
|
12. Load four dirs with custom settings at once
|
||||||
13. Show notifications on cp, mv completion
|
13. Notifications on cp, mv, rm completion
|
||||||
14. Auto-sync selection to system clipboard
|
14. Auto-sync selection to system clipboard
|
||||||
15. Open text files detached in another pane/tab/window
|
15. Open text files detached in another pane/tab/window
|
||||||
16. Create files/dirs/duplicates with parents (like `mkdir -p`)
|
16. Create files/dirs/duplicates with parents (like `mkdir -p`)
|
||||||
|
|
48
src/nnn.c
48
src/nnn.c
|
@ -688,7 +688,7 @@ static haiku_nm_h haiku_hnd;
|
||||||
#endif /* __GNUC__ */
|
#endif /* __GNUC__ */
|
||||||
|
|
||||||
/* Forward declarations */
|
/* Forward declarations */
|
||||||
static size_t xstrsncpy(char *dest, const char *src, size_t n);
|
static size_t xstrsncpy(char *restrict dst, const char *restrict src, size_t n);
|
||||||
static void redraw(char *path);
|
static void redraw(char *path);
|
||||||
static int spawn(char *file, char *arg1, char *arg2, const char *dir, uchar flag);
|
static int spawn(char *file, char *arg1, char *arg2, const char *dir, uchar flag);
|
||||||
static int (*nftw_fn)(const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf);
|
static int (*nftw_fn)(const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf);
|
||||||
|
@ -888,21 +888,22 @@ static rlim_t max_openfds(void)
|
||||||
struct rlimit rl;
|
struct rlimit rl;
|
||||||
rlim_t limit = getrlimit(RLIMIT_NOFILE, &rl);
|
rlim_t limit = getrlimit(RLIMIT_NOFILE, &rl);
|
||||||
|
|
||||||
if (limit != 0)
|
if (!limit) {
|
||||||
return 32;
|
limit = rl.rlim_cur;
|
||||||
|
rl.rlim_cur = rl.rlim_max;
|
||||||
|
|
||||||
limit = rl.rlim_cur;
|
/* Return ~75% of max possible */
|
||||||
rl.rlim_cur = rl.rlim_max;
|
if (setrlimit(RLIMIT_NOFILE, &rl) == 0) {
|
||||||
|
limit = rl.rlim_max - (rl.rlim_max >> 2);
|
||||||
/* Return ~75% of max possible */
|
/*
|
||||||
if (setrlimit(RLIMIT_NOFILE, &rl) == 0) {
|
* 20K is arbitrary. If the limit is set to max possible
|
||||||
limit = rl.rlim_max - (rl.rlim_max >> 2);
|
* value, the memory usage increases to more than double.
|
||||||
/*
|
*/
|
||||||
* 20K is arbitrary. If the limit is set to max possible
|
if (limit > 20480)
|
||||||
* value, the memory usage increases to more than double.
|
limit = 20480;
|
||||||
*/
|
}
|
||||||
return limit > 20480 ? 20480 : limit;
|
} else
|
||||||
}
|
limit = 32;
|
||||||
|
|
||||||
return limit;
|
return limit;
|
||||||
}
|
}
|
||||||
|
@ -930,21 +931,16 @@ static void *xrealloc(void *pcur, size_t len)
|
||||||
* Always null ('\0') terminates if both src and dest are valid pointers.
|
* Always null ('\0') terminates if both src and dest are valid pointers.
|
||||||
* Returns the number of bytes copied including terminating null byte.
|
* Returns the number of bytes copied including terminating null byte.
|
||||||
*/
|
*/
|
||||||
static size_t xstrsncpy(char *dest, const char *src, size_t n)
|
static size_t xstrsncpy(char *restrict dst, const char *restrict src, size_t n)
|
||||||
{
|
{
|
||||||
if (!src || !dest || !n)
|
char *end = memccpy(dst, src, '\0', n);
|
||||||
return 0;
|
|
||||||
|
|
||||||
size_t len = strlen(src) + 1;
|
if (!end) {
|
||||||
if (len <= n) {
|
dst[n - 1] = '\0';
|
||||||
memcpy(dest, src, len);
|
end = dst + n;
|
||||||
n = len;
|
|
||||||
} else {
|
|
||||||
memcpy(dest, src, n - 1);
|
|
||||||
dest[n - 1] = '\0';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return n;
|
return end - dst;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool is_suffix(const char *str, const char *suffix)
|
static bool is_suffix(const char *str, const char *suffix)
|
||||||
|
|
Loading…
Reference in a new issue