1414
1515#define _CRT_SECURE_NO_DEPRECATE
1616#include <windows.h>
17+ #ifdef _MSC_VER
1718#pragma comment (lib, "user32.lib")
1819#pragma comment (lib, "kernel32.lib")
20+ #endif
1921#include <stdio.h>
2022#include <math.h>
2123
3739/* protos */
3840
3941static int CheckForCompilerFeature (const char * option );
40- static int CheckForLinkerFeature (const char * * options , int count );
42+ static int CheckForLinkerFeature (char * * options , int count );
4143static int IsIn (const char * string , const char * substring );
4244static int SubstituteFile (const char * substs , const char * filename );
4345static int QualifyPath (const char * path );
@@ -54,8 +56,8 @@ typedef struct {
5456 char buffer [STATICBUFFERSIZE ];
5557} pipeinfo ;
5658
57- pipeinfo Out = {INVALID_HANDLE_VALUE , '\0' };
58- pipeinfo Err = {INVALID_HANDLE_VALUE , '\0' };
59+ pipeinfo Out = {INVALID_HANDLE_VALUE , "" };
60+ pipeinfo Err = {INVALID_HANDLE_VALUE , "" };
5961
6062/*
6163 * exitcodes: 0 == no, 1 == yes, 2 == error
@@ -273,7 +275,7 @@ CheckForCompilerFeature(
273275 "Tried to launch: \"%s\", but got error [%u]: " , cmdline , err );
274276
275277 FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM |FORMAT_MESSAGE_IGNORE_INSERTS |
276- FORMAT_MESSAGE_MAX_WIDTH_MASK , 0L , err , 0 , (LPVOID )& msg [chars ],
278+ FORMAT_MESSAGE_MAX_WIDTH_MASK , 0L , err , 0 , (LPSTR )& msg [chars ],
277279 (300 - chars ), 0 );
278280 WriteFile (GetStdHandle (STD_ERROR_HANDLE ), msg , lstrlen (msg ), & err ,NULL );
279281 return 2 ;
@@ -326,7 +328,7 @@ CheckForCompilerFeature(
326328
327329static int
328330CheckForLinkerFeature (
329- const char * * options ,
331+ char * * options ,
330332 int count )
331333{
332334 STARTUPINFO si ;
@@ -407,7 +409,7 @@ CheckForLinkerFeature(
407409 "Tried to launch: \"%s\", but got error [%u]: " , cmdline , err );
408410
409411 FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM |FORMAT_MESSAGE_IGNORE_INSERTS |
410- FORMAT_MESSAGE_MAX_WIDTH_MASK , 0L , err , 0 , (LPVOID )& msg [chars ],
412+ FORMAT_MESSAGE_MAX_WIDTH_MASK , 0L , err , 0 , (LPSTR )& msg [chars ],
411413 (300 - chars ), 0 );
412414 WriteFile (GetStdHandle (STD_ERROR_HANDLE ), msg , lstrlen (msg ), & err ,NULL );
413415 return 2 ;
@@ -503,7 +505,6 @@ GetVersionFromFile(
503505 const char * match ,
504506 int numdots )
505507{
506- size_t cbBuffer = 100 ;
507508 static char szBuffer [100 ];
508509 char * szResult = NULL ;
509510 FILE * fp = fopen (filename , "rt" );
@@ -513,7 +514,7 @@ GetVersionFromFile(
513514 * Read data until we see our match string.
514515 */
515516
516- while (fgets (szBuffer , cbBuffer , fp ) != NULL ) {
517+ while (fgets (szBuffer , sizeof ( szBuffer ) , fp ) != NULL ) {
517518 LPSTR p , q ;
518519
519520 p = strstr (szBuffer , match );
@@ -523,7 +524,7 @@ GetVersionFromFile(
523524 */
524525
525526 p += strlen (match );
526- while (* p && !isdigit (* p )) {
527+ while (* p && !isdigit (( unsigned char ) * p )) {
527528 ++ p ;
528529 }
529530
@@ -532,14 +533,13 @@ GetVersionFromFile(
532533 */
533534
534535 q = p ;
535- while (* q && (strchr ("0123456789.ab" , * q )) && ((!strchr (".ab" , * q )
536- && ( !strchr ("ab" , q [-1 ])) || -- numdots ))) {
536+ while (* q && (strchr ("0123456789.ab" , * q )) && ((( !strchr (".ab" , * q )
537+ && !strchr ("ab" , q [-1 ])) || -- numdots ))) {
537538 ++ q ;
538539 }
539540
540- memcpy (szBuffer , p , q - p );
541- szBuffer [q - p ] = 0 ;
542- szResult = szBuffer ;
541+ * q = 0 ;
542+ szResult = p ;
543543 break ;
544544 }
545545 }
@@ -562,7 +562,7 @@ typedef struct list_item_t {
562562static list_item_t *
563563list_insert (list_item_t * * listPtrPtr , const char * key , const char * value )
564564{
565- list_item_t * itemPtr = malloc (sizeof (list_item_t ));
565+ list_item_t * itemPtr = ( list_item_t * ) malloc (sizeof (list_item_t ));
566566 if (itemPtr ) {
567567 itemPtr -> key = strdup (key );
568568 itemPtr -> value = strdup (value );
@@ -611,9 +611,7 @@ SubstituteFile(
611611 const char * substitutions ,
612612 const char * filename )
613613{
614- size_t cbBuffer = 1024 ;
615614 static char szBuffer [1024 ], szCopy [1024 ];
616- char * szResult = NULL ;
617615 list_item_t * substPtr = NULL ;
618616 FILE * fp , * sp ;
619617
@@ -626,7 +624,7 @@ SubstituteFile(
626624
627625 sp = fopen (substitutions , "rt" );
628626 if (sp != NULL ) {
629- while (fgets (szBuffer , cbBuffer , sp ) != NULL ) {
627+ while (fgets (szBuffer , sizeof ( szBuffer ) , sp ) != NULL ) {
630628 unsigned char * ks , * ke , * vs , * ve ;
631629 ks = (unsigned char * )szBuffer ;
632630 while (ks && * ks && isspace (* ks )) ++ ks ;
@@ -657,7 +655,7 @@ SubstituteFile(
657655 * Run the substitutions over each line of the input
658656 */
659657
660- while (fgets (szBuffer , cbBuffer , fp ) != NULL ) {
658+ while (fgets (szBuffer , sizeof ( szBuffer ) , fp ) != NULL ) {
661659 list_item_t * p = NULL ;
662660 for (p = substPtr ; p != NULL ; p = p -> nextPtr ) {
663661 char * m = strstr (szBuffer , p -> key );
@@ -674,7 +672,7 @@ SubstituteFile(
674672 memcpy (szBuffer , szCopy , sizeof (szCopy ));
675673 }
676674 }
677- printf (szBuffer );
675+ printf ("%s" , szBuffer );
678676 }
679677
680678 list_free (& substPtr );
@@ -725,7 +723,8 @@ static int LocateDependencyHelper(const char *dir, const char *keypath)
725723{
726724 HANDLE hSearch ;
727725 char path [MAX_PATH + 1 ];
728- int dirlen , keylen , ret ;
726+ size_t dirlen ;
727+ int keylen , ret ;
729728 WIN32_FIND_DATA finfo ;
730729
731730 if (dir == NULL || keypath == NULL )
@@ -792,7 +791,8 @@ static int LocateDependencyHelper(const char *dir, const char *keypath)
792791 */
793792static int LocateDependency (const char * keypath )
794793{
795- int i , ret ;
794+ size_t i ;
795+ int ret ;
796796 static const char * paths [] = {".." , "..\\.." , "..\\..\\.." };
797797
798798 for (i = 0 ; i < (sizeof (paths )/sizeof (paths [0 ])); ++ i ) {
0 commit comments