Skip to content

Commit 453de6b

Browse files
authored
Merge pull request github#3583 from MathiasVP/qldoc-for-unix-constants
C++: QLDoc for Constants
2 parents ae4f6ed + 0467995 commit 453de6b

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

cpp/ql/src/semmle/code/cpp/commons/unix/Constants.qll

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44

55
import cpp
66

7+
/**
8+
* Gets the number corresponding to the contents of `input` in base-8.
9+
* Note: the first character of `input` must be `0`. For example:
10+
* `parseOctal("012345") = 5349`.
11+
*/
712
bindingset[input]
813
int parseOctal(string input) {
914
input.charAt(0) = "0" and
@@ -15,44 +20,77 @@ int parseOctal(string input) {
1520
)
1621
}
1722

23+
/** Gets the number corresponding to the "set-user-ID on execute bit" in Unix. */
1824
int s_isuid() { result = parseOctal("04000") }
1925

26+
/** Gets the number corresponding to the "set-group-ID on execute bit" in Unix. */
2027
int s_isgid() { result = parseOctal("02000") }
2128

29+
/** Gets the number corresponding to the sticky bit in Unix. */
2230
int s_isvtx() { result = parseOctal("01000") }
2331

32+
/** Gets the number corresponding to the read permission bit for owner of the file in Unix. */
2433
int s_irusr() { result = parseOctal("0400") }
2534

35+
/** Gets the number corresponding to the write permission bit for owner of the file in Unix. */
2636
int s_iwusr() { result = parseOctal("0200") }
2737

38+
/** Gets the number corresponding to the execute permission bit for owner of the file in Unix. */
2839
int s_ixusr() { result = parseOctal("0100") }
2940

41+
/** Gets the number corresponding to the permissions `S_IRUSR | S_IWUSR | S_IXUSR` in Unix. */
3042
int s_irwxu() { result = s_irusr().bitOr(s_iwusr()).bitOr(s_ixusr()) }
3143

44+
/**
45+
* Gets the number corresponding to the read permission bit for the group
46+
* owner of the file in Unix.
47+
*/
3248
int s_irgrp() { result = s_irusr().bitShiftRight(3) }
3349

50+
/**
51+
* Gets the number corresponding to the write permission bit for the group
52+
* owner of the file in Unix.
53+
*/
3454
int s_iwgrp() { result = s_iwusr().bitShiftRight(3) }
3555

56+
/**
57+
* Gets the number corresponding to the execute permission bit for the group
58+
* owner of the file in Unix.
59+
*/
3660
int s_ixgrp() { result = s_ixusr().bitShiftRight(3) }
3761

62+
/** Gets the number corresponding to the permissions `S_IRGRP | S_IWGRP | S_IXGRP` in Unix. */
3863
int s_irwxg() { result = s_irwxu().bitShiftRight(3) }
3964

65+
/** Gets the number corresponding to the read permission bit for other users in Unix. */
4066
int s_iroth() { result = s_irgrp().bitShiftRight(3) }
4167

68+
/** Gets the number corresponding to the write permission bit for other users in Unix. */
4269
int s_iwoth() { result = s_iwgrp().bitShiftRight(3) }
4370

71+
/** Gets the number corresponding to the execute-or-search permission bit for other users in Unix. */
4472
int s_ixoth() { result = s_ixgrp().bitShiftRight(3) }
4573

74+
/** Gets the number corresponding to the permissions `S_IROTH | S_IWOTH | S_IXOTH` in Unix. */
4675
int s_irwxo() { result = s_irwxg().bitShiftRight(3) }
4776

77+
/**
78+
* Gets the number that can be used in a bitwise and with the file status flag
79+
* to produce a number representing the file access mode.
80+
*/
4881
int o_accmode() { result = parseOctal("0003") }
4982

83+
/** Gets the number corresponding to the read-only file access mode. */
5084
int o_rdonly() { result = parseOctal("00") }
5185

86+
/** Gets the number corresponding to the write-only file access mode. */
5287
int o_wronly() { result = parseOctal("01") }
5388

89+
/** Gets the number corresponding to the read-and-write file access mode. */
5490
int o_rdwr() { result = parseOctal("02") }
5591

92+
/** Gets the number corresponding to the file creation flag O_CREAT on Linux. */
5693
int o_creat() { result = parseOctal("0100") }
5794

95+
/** Gets the number corresponding to the file creation flag O_EXCL on Linux. */
5896
int o_excl() { result = parseOctal("0200") }

0 commit comments

Comments
 (0)