Skip to content

Commit c981907

Browse files
committed
fix: using fgets in a file descriptor
This commit fixes the use of fgets in a file descriptor, which would make it easier to use fopen instead of using fdopen.
1 parent b1e217b commit c981907

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

zygiskd/src/utils.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ void set_socket_create_context(const char *context) {
5858
return;
5959
}
6060

61-
if (write(context, 1, strlen(context), sockcreate) != strlen(context)) {
61+
if (write(sockcreate, context, strlen(context)) != (ssize_t)strlen(context)) {
6262
LOGE("fwrite: %s\n", strerror(errno));
6363
errno = 0;
6464

@@ -72,15 +72,15 @@ static void get_current_attr(char *output) {
7272
char path[PATH_MAX];
7373
snprintf(path, PATH_MAX, "/proc/self/attr/current");
7474

75-
int current = open(path, O_RDONLY | O_CLOEXEC);
76-
if (current == -1) {
75+
FILE *current = fopen(path, "r");
76+
if (current == NULL) {
7777
LOGE("Failed to open current: %s\n", strerror(errno));
7878
errno = 0;
7979

8080
return;
8181
}
8282

83-
if (fgets(output, PATH_MAX, fileno(current)) == NULL) {
83+
if (fgets(output, PATH_MAX, current) == NULL) {
8484
LOGE("fgets: %s\n", strerror(errno));
8585
errno = 0;
8686

0 commit comments

Comments
 (0)