Fossil SCM

In fossil patch, use gethostname() instead of shelling out to the hostname executable.

danshearer 2026-11-17 22:20 UTC test-suite-new
Commit 0b3f9b31aa328d46e3cd07bce00a9dab9820decf59400908a8005f6a9f6d114a
1 file changed +8 -12
+8 -12
--- src/patch.c
+++ src/patch.c
@@ -17,29 +17,25 @@
1717
**
1818
** This file contains code used to implement the "patch" command
1919
*/
2020
#include "config.h"
2121
#include "patch.h"
22
+#if defined(_WIN32)
23
+# include <winsock2.h>
24
+#endif
2225
#include <assert.h>
2326
2427
/*
2528
** Try to compute the name of the computer on which this process
2629
** is running.
2730
*/
2831
char *fossil_hostname(void){
29
- FILE *in;
30
- char zBuf[200];
31
- in = popen("hostname","r");
32
- if( in ){
33
- int n = fread(zBuf, 1, sizeof(zBuf)-1, in);
34
- while( n>0 && fossil_isspace(zBuf[n-1]) ){ n--; }
35
- if( n<0 ) n = 0;
36
- zBuf[n] = 0;
37
- pclose(in);
38
- return fossil_strdup(zBuf);
39
- }
40
- return 0;
32
+ char zBuf[256];
33
+ socket_global_init();
34
+ if( gethostname(zBuf, sizeof(zBuf))!=0 ) return 0;
35
+ zBuf[sizeof(zBuf)-1] = 0;
36
+ return fossil_strdup(zBuf);
4137
}
4238
4339
/*
4440
** Flags passed from the main patch_cmd() routine into subfunctions used
4541
** to implement the various subcommands.
4642
--- src/patch.c
+++ src/patch.c
@@ -17,29 +17,25 @@
17 **
18 ** This file contains code used to implement the "patch" command
19 */
20 #include "config.h"
21 #include "patch.h"
 
 
 
22 #include <assert.h>
23
24 /*
25 ** Try to compute the name of the computer on which this process
26 ** is running.
27 */
28 char *fossil_hostname(void){
29 FILE *in;
30 char zBuf[200];
31 in = popen("hostname","r");
32 if( in ){
33 int n = fread(zBuf, 1, sizeof(zBuf)-1, in);
34 while( n>0 && fossil_isspace(zBuf[n-1]) ){ n--; }
35 if( n<0 ) n = 0;
36 zBuf[n] = 0;
37 pclose(in);
38 return fossil_strdup(zBuf);
39 }
40 return 0;
41 }
42
43 /*
44 ** Flags passed from the main patch_cmd() routine into subfunctions used
45 ** to implement the various subcommands.
46
--- src/patch.c
+++ src/patch.c
@@ -17,29 +17,25 @@
17 **
18 ** This file contains code used to implement the "patch" command
19 */
20 #include "config.h"
21 #include "patch.h"
22 #if defined(_WIN32)
23 # include <winsock2.h>
24 #endif
25 #include <assert.h>
26
27 /*
28 ** Try to compute the name of the computer on which this process
29 ** is running.
30 */
31 char *fossil_hostname(void){
32 char zBuf[256];
33 socket_global_init();
34 if( gethostname(zBuf, sizeof(zBuf))!=0 ) return 0;
35 zBuf[sizeof(zBuf)-1] = 0;
36 return fossil_strdup(zBuf);
 
 
 
 
 
 
 
37 }
38
39 /*
40 ** Flags passed from the main patch_cmd() routine into subfunctions used
41 ** to implement the various subcommands.
42

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button