How to limit file size on commit?

This pre-commit hook will do the file size check: .git/hooks/pre-commit #!/bin/sh hard_limit=$(git config hooks.filesizehardlimit) soft_limit=$(git config hooks.filesizesoftlimit) : ${hard_limit:=10000000} : ${soft_limit:=500000} list_new_or_modified_files() { git diff –staged –name-status|sed -e ‘/^D/ d; /^D/! s/.\s\+//’ } unmunge() { local result=”${1#\”}” result=”${result%\”}” env echo -e “$result” } check_file_size() { n=0 while read -r munged_filename do f=”$(unmunge “$munged_filename”)” h=$(git ls-files … Read more

how to set close-on-exec by default

No and no. You simply need to be careful and set close-on-exec on all file descriptors you care about. Setting it is easy, though: #include <fcntl.h> fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC); #include <unistd.h> /* please don’t do this */ for (i = getdtablesize(); i –> 3;) { if ((flags = fcntl(i, F_GETFD)) != -1) … Read more

Whats the difference between sed -E and sed -e

From source code, -E is an undocumented option for compatibility with BSD sed. /* Undocumented, for compatibility with BSD sed. */ case ‘E’: case ‘r’: if (extended_regexp_flags) usage(4); extended_regexp_flags = REG_EXTENDED; break; And from manual, -E in BSD sed is used to support extended regular expressions.

How do I lock files using fopen()?

I would strongly disagree with the claim that fopen is prefered over open. It’s impossible to use fopen safely when writing a file in a directory that’s writable by other users due to symlink vulnerabilities/race conditions, since there is no O_EXCL option. If you need to use stdio on POSIX systems, it’s best to use … Read more