diff options
| author | 諏訪子 <suwako@076.moe> | 2024-06-18 01:40:09 +0900 |
|---|---|---|
| committer | 諏訪子 <suwako@076.moe> | 2024-06-18 01:40:09 +0900 |
| commit | 759ca0074f7275b0bd1e58bc88ad2779035c9fb8 (patch) | |
| tree | 6349a57c169242944af0080d3f70a58a4612e697 /src/user.c | |
| parent | 11c97887ef28e9b073d9abf1c2da70cd01491c9e (diff) | |
NetBSDでの修正
Diffstat (limited to 'src/user.c')
| -rw-r--r-- | src/user.c | 27 |
1 files changed, 16 insertions, 11 deletions
@@ -21,6 +21,20 @@ void display_user_name() { void display_user_host() { char buf[64]; +#ifdef __NetBSD__ + FILE *p = popen("hostname", "r"); + if (!p) { + perror("hostnameコマンドを見つけられません。"); + return; + } + + while (fgets(buf, sizeof(buf), p) != NULL) { + buf[strcspn(buf, "\n")] = '\0'; + printf("%s", buf); + } + + pclose(p); +#else const char *filename; #ifdef __OpenBSD__ filename = "/etc/myname"; @@ -29,7 +43,7 @@ void display_user_host() { #endif FILE *f = fopen(filename, "r"); if (!f) { - snprintf(buf, sizeof(buf), "「%s」を見つけられません。", filename); + snprintf(buf, sizeof(buf), "「%s」ファイルを見つけられません。", filename); perror(buf); return; } @@ -38,15 +52,6 @@ void display_user_host() { printf("%s", buf); } - /* char hostname[128]; */ - /* int cnt = 0; */ - /* for (int i = 0; i < 128; i++) { */ - /* unsigned char key; */ - /* fread(&key, sizeof(key), 1, f); */ - /* hostname[i] = key; */ - /* cnt += 1; */ - /* } */ - - /* hostname[cnt] = '\0'; */ fclose(f); +#endif } |
