Fossil SCM
In fossil patch, use gethostname() instead of shelling out to the hostname executable.
Commit
0b3f9b31aa328d46e3cd07bce00a9dab9820decf59400908a8005f6a9f6d114a
Parent
f46d4135396943c…
1 file changed
+8
-12
+8
-12
| --- src/patch.c | ||
| +++ src/patch.c | ||
| @@ -17,29 +17,25 @@ | ||
| 17 | 17 | ** |
| 18 | 18 | ** This file contains code used to implement the "patch" command |
| 19 | 19 | */ |
| 20 | 20 | #include "config.h" |
| 21 | 21 | #include "patch.h" |
| 22 | +#if defined(_WIN32) | |
| 23 | +# include <winsock2.h> | |
| 24 | +#endif | |
| 22 | 25 | #include <assert.h> |
| 23 | 26 | |
| 24 | 27 | /* |
| 25 | 28 | ** Try to compute the name of the computer on which this process |
| 26 | 29 | ** is running. |
| 27 | 30 | */ |
| 28 | 31 | 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); | |
| 41 | 37 | } |
| 42 | 38 | |
| 43 | 39 | /* |
| 44 | 40 | ** Flags passed from the main patch_cmd() routine into subfunctions used |
| 45 | 41 | ** to implement the various subcommands. |
| 46 | 42 |
| --- 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 |