forked from facebook/watchman
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgroups.cpp
34 lines (32 loc) · 828 Bytes
/
groups.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/* Copyright 2012-present Facebook, Inc.
* Licensed under the Apache License, Version 2.0 */
#include "watchman.h"
#include <folly/String.h>
#ifndef _WIN32
#include <errno.h>
#include <grp.h>
#include <string.h>
#include <sys/types.h>
#endif
#ifndef _WIN32
using namespace watchman;
const struct group* w_get_group(const char* group_name) {
// This explicit errno statement is necessary to distinguish between the
// group not existing and an error.
errno = 0;
struct group* group = getgrnam(group_name);
if (!group) {
if (errno == 0) {
logf(ERR, "group '{}' does not exist\n", group_name);
} else {
logf(
ERR,
"getting gid for '{}' failed: {}\n",
group_name,
folly::errnoStr(errno));
}
return nullptr;
}
return group;
}
#endif // ndef _WIN32