mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-27 06:48:31 +00:00
Improve docs of more system calls
This change also found a few POSIX compliance bugs with errnos. Another bug was discovered where, on Windows, pread() and pwrite() could modify the file position in cases where ReadFile() returned an error e.g. when seeking past the end of file. We also have more tests!
This commit is contained in:
parent
af24c19db3
commit
ccbae7799e
39 changed files with 589 additions and 175 deletions
|
@ -16,10 +16,12 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/assert.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/syscall-sysv.internal.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
#include "libc/limits.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/nt/accounting.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
|
@ -38,7 +40,7 @@ static textwindows dontinline uint32_t GetUserNameHash(void) {
|
|||
char16_t buf[257];
|
||||
uint32_t size = ARRAYLEN(buf);
|
||||
GetUserName(&buf, &size);
|
||||
return KnuthMultiplicativeHash32(buf, size >> 1);
|
||||
return KnuthMultiplicativeHash32(buf, size >> 1) & INT_MAX;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -47,18 +49,22 @@ static textwindows dontinline uint32_t GetUserNameHash(void) {
|
|||
* This never fails. On Windows, which doesn't really have this concept,
|
||||
* we return a deterministic value that's likely to work.
|
||||
*
|
||||
* @return user id (always successful)
|
||||
* @asyncsignalsafe
|
||||
* @threadsafe
|
||||
* @vforksafe
|
||||
*/
|
||||
uint32_t getuid(void) {
|
||||
uint32_t rc;
|
||||
if (!IsWindows()) {
|
||||
int rc;
|
||||
if (IsMetal()) {
|
||||
rc = 0;
|
||||
} else if (!IsWindows()) {
|
||||
rc = sys_getuid();
|
||||
} else {
|
||||
rc = GetUserNameHash();
|
||||
}
|
||||
|
||||
STRACE("%s() → %u% m", "getuid", rc);
|
||||
_npassert(rc >= 0);
|
||||
STRACE("%s() → %d", "getuid", rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
@ -68,16 +74,21 @@ uint32_t getuid(void) {
|
|||
* This never fails. On Windows, which doesn't really have this concept,
|
||||
* we return a deterministic value that's likely to work.
|
||||
*
|
||||
* @return group id (always successful)
|
||||
* @asyncsignalsafe
|
||||
* @threadsafe
|
||||
* @vforksafe
|
||||
*/
|
||||
uint32_t getgid(void) {
|
||||
uint32_t rc;
|
||||
if (!IsWindows()) {
|
||||
int rc;
|
||||
if (IsMetal()) {
|
||||
rc = 0;
|
||||
} else if (!IsWindows()) {
|
||||
rc = sys_getgid();
|
||||
} else {
|
||||
rc = GetUserNameHash();
|
||||
}
|
||||
STRACE("%s() → %u% m", "getgid", rc);
|
||||
_npassert(rc >= 0);
|
||||
STRACE("%s() → %d", "getgid", rc);
|
||||
return rc;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue