Changed fgetc variables to int

fgetc used "char c" for all returns. Unfortunately this doesn't work for
all architectures. So an "int b" variable was created to recieve the
return before casting it into c.
stable
Justin Reichardt 2021-09-17 12:53:31 -05:00
parent d125a99347
commit a8677c97c9
2 changed files with 39 additions and 27 deletions

View File

@ -124,33 +124,37 @@ int copy_old_download(char *url){
char search[MAXSTRSIZE] = "# rhosts download - ";
strncat(search,url,MAXSTRSIZE - 21);
char c = '\0';
int b =0;
do{
c = fgetc(hostsf);
while(c != '\n' && c != EOF && strlen(buff) < MAXSTRSIZE){
b = fgetc(hostsf);
c = (char)b;
while(c != '\n' && b != EOF && strlen(buff) < MAXSTRSIZE){
strncat(buff, &c, 1);
c = fgetc(hostsf);
b = fgetc(hostsf);
c = (char)b;
}
strncat(buff, &c, 1);
if(strncmp(buff,search, strlen(search)) == 0){
printf("Found a local match for %s\n",url);
c = EOF;
b = EOF;
}
buff[0] = '\0';
}while(c !=EOF);
}while(b !=EOF);
do{
do{
c = fgetc(hostsf);
if (c != EOF)
b = fgetc(hostsf);
c = (char)b;
if (b != EOF)
strncat(buff, &c, 1);
} while(c != '\n' && c != EOF && strlen(buff) < MAXSTRSIZE);
} while(c != '\n' && b != EOF && strlen(buff) < MAXSTRSIZE);
if(strncmp(buff,"# rhosts", 8) != 0){
fputs(buff, tmpf);
}
else
c = EOF;
b = EOF;
buff[0] = '\0';
}while(c !=EOF);
}while(b !=EOF);
fclose(hostsf);
fclose(tmpf);
@ -170,18 +174,20 @@ int clean_download(){
return 1;
}
char c;
int b;
char buff[MAXSTRSIZE];
int buffsize=1;
buff[0] = '\0';
do{
c = fgetc(tmpdf);
b = fgetc(tmpdf);
c = (char)b;
buffsize++;
if (buffsize > MAXSTRSIZE){
printf("String too long when cleaning download: %s\n",buff);
return 1;
}
if (c!=EOF) // Later needs to check for NULL
if (b!=EOF) // Later needs to check for NULL
strncat(buff,&c,1);
if (buffsize==2){
if (buff[0]=='#' || buff[0]=='\n'){
@ -190,12 +196,12 @@ int clean_download(){
buffsize=1;
}
}
if (c == '\n' || c == EOF){
if (c == '\n' || b == EOF){
fputs(buff,tmpf);
buff[0]='\0';
buffsize=1;
}
}while (c!=EOF);
}while (b!=EOF);
fflush(tmpf);
fclose(tmpf);
fclose(tmpdf);
@ -203,8 +209,10 @@ int clean_download(){
}
int skip_to_next_line(FILE **fp){
char c;
int b;
do{
c = fgetc(*fp);
}while(c != '\n' && c != EOF);
b = fgetc(*fp);
c = (char)b;
}while(c != '\n' && b != EOF);
return 0;
}

View File

@ -70,17 +70,19 @@ int parse_config(struct entry **entries){
j = &(*entries)[0].entrytype;
char c='\0';
int b=0;
char buff[MAXSTRSIZE];
buff[0]='\0';
short int valtyp = CONTENTTYPE_BLANK;
// Loop through config file
do{
c = fgetc(configfile);
b = fgetc(configfile);
c = (char)b;
// Detect if a comment
if (strncmp(buff, "#",(long unsigned int)1) == 0 && \
valtyp == CONTENTTYPE_BLANK){
while (c != '\n' && c != EOF){c =fgetc(configfile);}
while (c != '\n' && b != EOF){c =fgetc(configfile);}
}
// Detect end of value type string
if (c == '=' && valtyp == CONTENTTYPE_BLANK){
@ -92,7 +94,7 @@ int parse_config(struct entry **entries){
}
// Detect end of entry
else if ((c == '\n' || c == EOF) \
else if ((c == '\n' || b == EOF) \
&& valtyp != CONTENTTYPE_BLANK){
(*entries)[0].entrytype++;
*entries = (struct entry *)realloc(*entries,\
@ -104,13 +106,13 @@ int parse_config(struct entry **entries){
buff[0] = '\0';
valtyp = CONTENTTYPE_BLANK;
}
else if (c == '\n' || c == EOF){
else if (c == '\n' || b == EOF){
buff[0] = '\0';
}
else{
strncat(buff, &c, 1);
}
}while (c != EOF);
}while (b != EOF);
rc = fclose(configfile);
if (rc != 0){return 1;}
@ -134,13 +136,15 @@ int preserve_static_entries(){
}
char buff[MAXSTRSIZE];
char c = EOF;
int b = 0;
int rc = 0;
printf("Static hosts are:\n");
do{
c = fgetc(hostsf);
b = fgetc(hostsf);
c = (char)b;
strncat(buff, &c, 1);
if (strncmp(buff, "# rhosts begin", 14) == 0){c = EOF;}
if (strncmp(buff, "# rhosts begin", 14) == 0){b = EOF;}
if (c == '\n'){
rc = fputs(buff, tmpf);
if (rc == EOF){
@ -151,7 +155,7 @@ int preserve_static_entries(){
printf("%s",buff);
buff[0] = '\0';
}
}while ( c != EOF);
}while ( b != EOF);
rc = fputs("# rhosts begin\n", tmpf);
if (rc == EOF){
fclose(hostsf);
@ -212,10 +216,10 @@ int copy_tmp_to_hosts(){
fclose(tmpf);
return 1;
}
char c;
int b;
for(c = fgetc(tmpf);c != EOF;c = fgetc(tmpf)){
fputc(c,hostsf);
for(b = fgetc(tmpf);b != EOF;b = fgetc(tmpf)){
fputc((char)b,hostsf);
}
remove(TMPLOCATION);
return 0;