* win32_slim.h: includes the minimal version of windows.h
modified:
 * cthread: added lock_t c++ class
 * os: added getUserName()
 * socket: modified socket_len_t to sk_len_t to better follow naming convetions in file
 * str: added operator std::string() to str_t
This commit is contained in:
alessandrobason 2021-11-24 10:15:47 +00:00
parent 7fdc8b5301
commit bce93361b1
16 changed files with 187 additions and 70 deletions

28
os.c
View file

@ -7,6 +7,8 @@
#ifdef _WIN32
#define _BUFSZ 128
#include <lmcons.h>
// modified from netbsd source http://cvsweb.netbsd.org/bsdweb.cgi/pkgsrc/pkgtools/libnbcompat/files/getdelim.c?only_with_tag=MAIN
ssize_t getdelim(char **buf, size_t *bufsz, int delimiter, FILE *fp) {
char *ptr, *eptr;
@ -64,4 +66,30 @@ ssize_t getdelim(char **buf, size_t *bufsz, int delimiter, FILE *fp) {
ssize_t getline(char **line_ptr, size_t *n, FILE *stream) {
return getdelim(line_ptr, n, '\n', stream);
}
str_t getUserName() {
char buf[UNLEN + 1];
DWORD sz = sizeof(buf);
BOOL res = GetUserNameA(buf, &sz);
if(!res) {
return strInit();
}
return strInitBuf(buf, sz);
}
#else
#include <unistd.h>
#include <stdio.h>
#include <errno.h>
str_t getUserName() {
char buf[255];
int res = getlogin_r(buf, sizeof(buf));
if(res) {
return strInit();
}
return strInitStr(buf);
}
#endif