Fossil SCM

Move the file-specific definitions of the isatty() and fileno() macros into util.c's fossil_isatty() and fossil_fileno() in prep for an upcoming change which needs isatty().

stephan 2024-08-27 11:06 trunk
Commit 898a70ce82a524ca054ed77dfab897b9383337d0c645a039e2ff78e49b60c3ce
+1 -1
--- src/cgi.c
+++ src/cgi.c
@@ -2122,11 +2122,11 @@
21222122
for(i=0; zToken[i] && zToken[i]!='?'; i++){}
21232123
if( zToken[i] ) zToken[i++] = 0;
21242124
cgi_setenv("PATH_INFO", zToken);
21252125
cgi_setenv("QUERY_STRING", &zToken[i]);
21262126
if( zIpAddr==0 ){
2127
- zIpAddr = cgi_remote_ip(fileno(g.httpIn));
2127
+ zIpAddr = cgi_remote_ip(fossil_fileno(g.httpIn));
21282128
}
21292129
if( zIpAddr ){
21302130
cgi_setenv("REMOTE_ADDR", zIpAddr);
21312131
g.zIpAddr = fossil_strdup(zIpAddr);
21322132
}
21332133
--- src/cgi.c
+++ src/cgi.c
@@ -2122,11 +2122,11 @@
2122 for(i=0; zToken[i] && zToken[i]!='?'; i++){}
2123 if( zToken[i] ) zToken[i++] = 0;
2124 cgi_setenv("PATH_INFO", zToken);
2125 cgi_setenv("QUERY_STRING", &zToken[i]);
2126 if( zIpAddr==0 ){
2127 zIpAddr = cgi_remote_ip(fileno(g.httpIn));
2128 }
2129 if( zIpAddr ){
2130 cgi_setenv("REMOTE_ADDR", zIpAddr);
2131 g.zIpAddr = fossil_strdup(zIpAddr);
2132 }
2133
--- src/cgi.c
+++ src/cgi.c
@@ -2122,11 +2122,11 @@
2122 for(i=0; zToken[i] && zToken[i]!='?'; i++){}
2123 if( zToken[i] ) zToken[i++] = 0;
2124 cgi_setenv("PATH_INFO", zToken);
2125 cgi_setenv("QUERY_STRING", &zToken[i]);
2126 if( zIpAddr==0 ){
2127 zIpAddr = cgi_remote_ip(fossil_fileno(g.httpIn));
2128 }
2129 if( zIpAddr ){
2130 cgi_setenv("REMOTE_ADDR", zIpAddr);
2131 g.zIpAddr = fossil_strdup(zIpAddr);
2132 }
2133
+1 -7
--- src/http.c
+++ src/http.c
@@ -21,16 +21,10 @@
2121
#include "http.h"
2222
#include <assert.h>
2323
2424
#ifdef _WIN32
2525
#include <io.h>
26
-#ifndef isatty
27
-#define isatty(d) _isatty(d)
28
-#endif
29
-#ifndef fileno
30
-#define fileno(s) _fileno(s)
31
-#endif
3226
#endif
3327
3428
3529
#if INTERFACE
3630
/*
@@ -206,11 +200,11 @@
206200
Blob x;
207201
char *zUser;
208202
char *zPw;
209203
char *zPrompt;
210204
char *zHttpAuth = 0;
211
- if( !isatty(fileno(stdin)) ) return 0;
205
+ if( !fossil_isatty(fossil_fileno(stdin)) ) return 0;
212206
zPrompt = mprintf("\n%s authorization required by\n%s\n",
213207
g.url.isHttps==1 ? "Encrypted HTTPS" : "Unencrypted HTTP", g.url.canonical);
214208
fossil_print("%s", zPrompt);
215209
free(zPrompt);
216210
if ( g.url.user && g.url.passwd && use_fossil_creds_for_httpauth_prompt() ){
217211
--- src/http.c
+++ src/http.c
@@ -21,16 +21,10 @@
21 #include "http.h"
22 #include <assert.h>
23
24 #ifdef _WIN32
25 #include <io.h>
26 #ifndef isatty
27 #define isatty(d) _isatty(d)
28 #endif
29 #ifndef fileno
30 #define fileno(s) _fileno(s)
31 #endif
32 #endif
33
34
35 #if INTERFACE
36 /*
@@ -206,11 +200,11 @@
206 Blob x;
207 char *zUser;
208 char *zPw;
209 char *zPrompt;
210 char *zHttpAuth = 0;
211 if( !isatty(fileno(stdin)) ) return 0;
212 zPrompt = mprintf("\n%s authorization required by\n%s\n",
213 g.url.isHttps==1 ? "Encrypted HTTPS" : "Unencrypted HTTP", g.url.canonical);
214 fossil_print("%s", zPrompt);
215 free(zPrompt);
216 if ( g.url.user && g.url.passwd && use_fossil_creds_for_httpauth_prompt() ){
217
--- src/http.c
+++ src/http.c
@@ -21,16 +21,10 @@
21 #include "http.h"
22 #include <assert.h>
23
24 #ifdef _WIN32
25 #include <io.h>
 
 
 
 
 
 
26 #endif
27
28
29 #if INTERFACE
30 /*
@@ -206,11 +200,11 @@
200 Blob x;
201 char *zUser;
202 char *zPw;
203 char *zPrompt;
204 char *zHttpAuth = 0;
205 if( !fossil_isatty(fossil_fileno(stdin)) ) return 0;
206 zPrompt = mprintf("\n%s authorization required by\n%s\n",
207 g.url.isHttps==1 ? "Encrypted HTTPS" : "Unencrypted HTTP", g.url.canonical);
208 fossil_print("%s", zPrompt);
209 free(zPrompt);
210 if ( g.url.user && g.url.passwd && use_fossil_creds_for_httpauth_prompt() ){
211
+1 -2
--- src/main.c
+++ src/main.c
@@ -21,11 +21,10 @@
2121
#include "VERSION.h"
2222
#include "config.h"
2323
#if defined(_WIN32)
2424
# include <windows.h>
2525
# include <io.h>
26
-# define isatty(h) _isatty(h)
2726
# define GETPID (int)GetCurrentProcessId
2827
#endif
2928
3029
/* BUGBUG: This (PID_T) does not work inside of INTERFACE block. */
3130
#if USE_SEE
@@ -705,11 +704,11 @@
705704
int rc;
706705
707706
g.zPhase = "init";
708707
#if !defined(_WIN32_WCE)
709708
if( fossil_getenv("FOSSIL_BREAK") ){
710
- if( isatty(0) && isatty(2) ){
709
+ if( fossil_isatty(0) && fossil_isatty(2) ){
711710
fprintf(stderr,
712711
"attach debugger to process %d and press any key to continue.\n",
713712
GETPID());
714713
fgetc(stdin);
715714
}else{
716715
--- src/main.c
+++ src/main.c
@@ -21,11 +21,10 @@
21 #include "VERSION.h"
22 #include "config.h"
23 #if defined(_WIN32)
24 # include <windows.h>
25 # include <io.h>
26 # define isatty(h) _isatty(h)
27 # define GETPID (int)GetCurrentProcessId
28 #endif
29
30 /* BUGBUG: This (PID_T) does not work inside of INTERFACE block. */
31 #if USE_SEE
@@ -705,11 +704,11 @@
705 int rc;
706
707 g.zPhase = "init";
708 #if !defined(_WIN32_WCE)
709 if( fossil_getenv("FOSSIL_BREAK") ){
710 if( isatty(0) && isatty(2) ){
711 fprintf(stderr,
712 "attach debugger to process %d and press any key to continue.\n",
713 GETPID());
714 fgetc(stdin);
715 }else{
716
--- src/main.c
+++ src/main.c
@@ -21,11 +21,10 @@
21 #include "VERSION.h"
22 #include "config.h"
23 #if defined(_WIN32)
24 # include <windows.h>
25 # include <io.h>
 
26 # define GETPID (int)GetCurrentProcessId
27 #endif
28
29 /* BUGBUG: This (PID_T) does not work inside of INTERFACE block. */
30 #if USE_SEE
@@ -705,11 +704,11 @@
704 int rc;
705
706 g.zPhase = "init";
707 #if !defined(_WIN32_WCE)
708 if( fossil_getenv("FOSSIL_BREAK") ){
709 if( fossil_isatty(0) && fossil_isatty(2) ){
710 fprintf(stderr,
711 "attach debugger to process %d and press any key to continue.\n",
712 GETPID());
713 fgetc(stdin);
714 }else{
715
+1 -1
--- src/printf.c
+++ src/printf.c
@@ -1269,8 +1269,8 @@
12691269
void fossil_binary_mode(FILE *p){
12701270
#if defined(_WIN32)
12711271
_setmode(_fileno(p), _O_BINARY);
12721272
#endif
12731273
#ifdef __EMX__ /* OS/2 */
1274
- setmode(fileno(p), O_BINARY);
1274
+ fossil_setmode(fossil_fileno(p), O_BINARY);
12751275
#endif
12761276
}
12771277
--- src/printf.c
+++ src/printf.c
@@ -1269,8 +1269,8 @@
1269 void fossil_binary_mode(FILE *p){
1270 #if defined(_WIN32)
1271 _setmode(_fileno(p), _O_BINARY);
1272 #endif
1273 #ifdef __EMX__ /* OS/2 */
1274 setmode(fileno(p), O_BINARY);
1275 #endif
1276 }
1277
--- src/printf.c
+++ src/printf.c
@@ -1269,8 +1269,8 @@
1269 void fossil_binary_mode(FILE *p){
1270 #if defined(_WIN32)
1271 _setmode(_fileno(p), _O_BINARY);
1272 #endif
1273 #ifdef __EMX__ /* OS/2 */
1274 fossil_setmode(fossil_fileno(p), O_BINARY);
1275 #endif
1276 }
1277
+4 -9
--- src/url.c
+++ src/url.c
@@ -21,16 +21,10 @@
2121
#include "url.h"
2222
#include <stdio.h>
2323
2424
#ifdef _WIN32
2525
#include <io.h>
26
-#ifndef isatty
27
-#define isatty(d) _isatty(d)
28
-#endif
29
-#ifndef fileno
30
-#define fileno(s) _fileno(s)
31
-#endif
3226
#endif
3327
3428
#if INTERFACE
3529
/*
3630
** Flags for url_parse()
@@ -324,11 +318,12 @@
324318
blob_reset(&cfile);
325319
}else if( pUrlData->user!=0 && pUrlData->passwd==0
326320
&& (urlFlags & URL_PROMPT_PW)!=0 ){
327321
url_prompt_for_password_local(pUrlData);
328322
}else if( pUrlData->user!=0 && ( urlFlags & URL_ASK_REMEMBER_PW ) ){
329
- if( isatty(fileno(stdin)) && ( urlFlags & URL_REMEMBER_PW )==0 ){
323
+ if( fossil_isatty(fossil_fileno(stdin))
324
+ && ( urlFlags & URL_REMEMBER_PW )==0 ){
330325
if( save_password_prompt(pUrlData->passwd) ){
331326
pUrlData->flags = urlFlags |= URL_REMEMBER_PW;
332327
}else{
333328
pUrlData->flags = urlFlags &= ~URL_REMEMBER_PW;
334329
}
@@ -735,11 +730,11 @@
735730
** the provided UrlData structure. Store the result into the "passwd" member
736731
** of the provided UrlData structure.
737732
*/
738733
void url_prompt_for_password_local(UrlData *pUrlData){
739734
if( pUrlData->isSsh || pUrlData->isFile ) return;
740
- if( isatty(fileno(stdin))
735
+ if( fossil_isatty(fossil_fileno(stdin))
741736
&& (pUrlData->flags & URL_PROMPT_PW)!=0
742737
&& (pUrlData->flags & URL_PROMPTED)==0
743738
){
744739
pUrlData->flags |= URL_PROMPTED;
745740
pUrlData->passwd = prompt_for_user_password(pUrlData->canonical);
@@ -796,11 +791,11 @@
796791
** URL but no password.
797792
*/
798793
void url_get_password_if_needed(void){
799794
if( (g.url.user && g.url.user[0])
800795
&& (g.url.passwd==0 || g.url.passwd[0]==0)
801
- && isatty(fileno(stdin))
796
+ && fossil_isatty(fossil_fileno(stdin))
802797
){
803798
url_prompt_for_password();
804799
}
805800
}
806801
807802
--- src/url.c
+++ src/url.c
@@ -21,16 +21,10 @@
21 #include "url.h"
22 #include <stdio.h>
23
24 #ifdef _WIN32
25 #include <io.h>
26 #ifndef isatty
27 #define isatty(d) _isatty(d)
28 #endif
29 #ifndef fileno
30 #define fileno(s) _fileno(s)
31 #endif
32 #endif
33
34 #if INTERFACE
35 /*
36 ** Flags for url_parse()
@@ -324,11 +318,12 @@
324 blob_reset(&cfile);
325 }else if( pUrlData->user!=0 && pUrlData->passwd==0
326 && (urlFlags & URL_PROMPT_PW)!=0 ){
327 url_prompt_for_password_local(pUrlData);
328 }else if( pUrlData->user!=0 && ( urlFlags & URL_ASK_REMEMBER_PW ) ){
329 if( isatty(fileno(stdin)) && ( urlFlags & URL_REMEMBER_PW )==0 ){
 
330 if( save_password_prompt(pUrlData->passwd) ){
331 pUrlData->flags = urlFlags |= URL_REMEMBER_PW;
332 }else{
333 pUrlData->flags = urlFlags &= ~URL_REMEMBER_PW;
334 }
@@ -735,11 +730,11 @@
735 ** the provided UrlData structure. Store the result into the "passwd" member
736 ** of the provided UrlData structure.
737 */
738 void url_prompt_for_password_local(UrlData *pUrlData){
739 if( pUrlData->isSsh || pUrlData->isFile ) return;
740 if( isatty(fileno(stdin))
741 && (pUrlData->flags & URL_PROMPT_PW)!=0
742 && (pUrlData->flags & URL_PROMPTED)==0
743 ){
744 pUrlData->flags |= URL_PROMPTED;
745 pUrlData->passwd = prompt_for_user_password(pUrlData->canonical);
@@ -796,11 +791,11 @@
796 ** URL but no password.
797 */
798 void url_get_password_if_needed(void){
799 if( (g.url.user && g.url.user[0])
800 && (g.url.passwd==0 || g.url.passwd[0]==0)
801 && isatty(fileno(stdin))
802 ){
803 url_prompt_for_password();
804 }
805 }
806
807
--- src/url.c
+++ src/url.c
@@ -21,16 +21,10 @@
21 #include "url.h"
22 #include <stdio.h>
23
24 #ifdef _WIN32
25 #include <io.h>
 
 
 
 
 
 
26 #endif
27
28 #if INTERFACE
29 /*
30 ** Flags for url_parse()
@@ -324,11 +318,12 @@
318 blob_reset(&cfile);
319 }else if( pUrlData->user!=0 && pUrlData->passwd==0
320 && (urlFlags & URL_PROMPT_PW)!=0 ){
321 url_prompt_for_password_local(pUrlData);
322 }else if( pUrlData->user!=0 && ( urlFlags & URL_ASK_REMEMBER_PW ) ){
323 if( fossil_isatty(fossil_fileno(stdin))
324 && ( urlFlags & URL_REMEMBER_PW )==0 ){
325 if( save_password_prompt(pUrlData->passwd) ){
326 pUrlData->flags = urlFlags |= URL_REMEMBER_PW;
327 }else{
328 pUrlData->flags = urlFlags &= ~URL_REMEMBER_PW;
329 }
@@ -735,11 +730,11 @@
730 ** the provided UrlData structure. Store the result into the "passwd" member
731 ** of the provided UrlData structure.
732 */
733 void url_prompt_for_password_local(UrlData *pUrlData){
734 if( pUrlData->isSsh || pUrlData->isFile ) return;
735 if( fossil_isatty(fossil_fileno(stdin))
736 && (pUrlData->flags & URL_PROMPT_PW)!=0
737 && (pUrlData->flags & URL_PROMPTED)==0
738 ){
739 pUrlData->flags |= URL_PROMPTED;
740 pUrlData->passwd = prompt_for_user_password(pUrlData->canonical);
@@ -796,11 +791,11 @@
791 ** URL but no password.
792 */
793 void url_get_password_if_needed(void){
794 if( (g.url.user && g.url.user[0])
795 && (g.url.passwd==0 || g.url.passwd[0]==0)
796 && fossil_isatty(fossil_fileno(stdin))
797 ){
798 url_prompt_for_password();
799 }
800 }
801
802
+23
--- src/util.c
+++ src/util.c
@@ -28,19 +28,42 @@
2828
/*
2929
** For the fossil_timer_xxx() family of functions...
3030
*/
3131
#ifdef _WIN32
3232
# include <windows.h>
33
+# include <io.h>
3334
#else
3435
# include <sys/time.h>
3536
# include <sys/resource.h>
3637
# include <sys/types.h>
3738
# include <sys/stat.h>
3839
# include <unistd.h>
3940
# include <fcntl.h>
4041
# include <errno.h>
4142
#endif
43
+
44
+/*
45
+** Returns the same as the platform's isatty() or _isatty() function.
46
+*/
47
+int fossil_isatty(int fd){
48
+#ifdef _WIN32
49
+ return _isatty(fd);
50
+#else
51
+ return isatty(fd);
52
+#endif
53
+}
54
+
55
+/*
56
+** Returns the same as the platform's fileno() or _fileno() function.
57
+*/
58
+int fossil_fileno(FILE *p){
59
+#ifdef _WIN32
60
+ return _fileno(p);
61
+#else
62
+ return fileno(p);
63
+#endif
64
+}
4265
4366
/*
4467
** Exit. Take care to close the database first.
4568
*/
4669
NORETURN void fossil_exit(int rc){
4770
--- src/util.c
+++ src/util.c
@@ -28,19 +28,42 @@
28 /*
29 ** For the fossil_timer_xxx() family of functions...
30 */
31 #ifdef _WIN32
32 # include <windows.h>
 
33 #else
34 # include <sys/time.h>
35 # include <sys/resource.h>
36 # include <sys/types.h>
37 # include <sys/stat.h>
38 # include <unistd.h>
39 # include <fcntl.h>
40 # include <errno.h>
41 #endif
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
43 /*
44 ** Exit. Take care to close the database first.
45 */
46 NORETURN void fossil_exit(int rc){
47
--- src/util.c
+++ src/util.c
@@ -28,19 +28,42 @@
28 /*
29 ** For the fossil_timer_xxx() family of functions...
30 */
31 #ifdef _WIN32
32 # include <windows.h>
33 # include <io.h>
34 #else
35 # include <sys/time.h>
36 # include <sys/resource.h>
37 # include <sys/types.h>
38 # include <sys/stat.h>
39 # include <unistd.h>
40 # include <fcntl.h>
41 # include <errno.h>
42 #endif
43
44 /*
45 ** Returns the same as the platform's isatty() or _isatty() function.
46 */
47 int fossil_isatty(int fd){
48 #ifdef _WIN32
49 return _isatty(fd);
50 #else
51 return isatty(fd);
52 #endif
53 }
54
55 /*
56 ** Returns the same as the platform's fileno() or _fileno() function.
57 */
58 int fossil_fileno(FILE *p){
59 #ifdef _WIN32
60 return _fileno(p);
61 #else
62 return fileno(p);
63 #endif
64 }
65
66 /*
67 ** Exit. Take care to close the database first.
68 */
69 NORETURN void fossil_exit(int rc){
70

Keyboard Shortcuts

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