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
parent
d125a99347
commit
a8677c97c9
|
|
@ -124,33 +124,37 @@ int copy_old_download(char *url){
|
||||||
char search[MAXSTRSIZE] = "# rhosts download - ";
|
char search[MAXSTRSIZE] = "# rhosts download - ";
|
||||||
strncat(search,url,MAXSTRSIZE - 21);
|
strncat(search,url,MAXSTRSIZE - 21);
|
||||||
char c = '\0';
|
char c = '\0';
|
||||||
|
int b =0;
|
||||||
|
|
||||||
do{
|
do{
|
||||||
c = fgetc(hostsf);
|
b = fgetc(hostsf);
|
||||||
while(c != '\n' && c != EOF && strlen(buff) < MAXSTRSIZE){
|
c = (char)b;
|
||||||
|
while(c != '\n' && b != EOF && strlen(buff) < MAXSTRSIZE){
|
||||||
strncat(buff, &c, 1);
|
strncat(buff, &c, 1);
|
||||||
c = fgetc(hostsf);
|
b = fgetc(hostsf);
|
||||||
|
c = (char)b;
|
||||||
}
|
}
|
||||||
strncat(buff, &c, 1);
|
strncat(buff, &c, 1);
|
||||||
if(strncmp(buff,search, strlen(search)) == 0){
|
if(strncmp(buff,search, strlen(search)) == 0){
|
||||||
printf("Found a local match for %s\n",url);
|
printf("Found a local match for %s\n",url);
|
||||||
c = EOF;
|
b = EOF;
|
||||||
}
|
}
|
||||||
buff[0] = '\0';
|
buff[0] = '\0';
|
||||||
}while(c !=EOF);
|
}while(b !=EOF);
|
||||||
do{
|
do{
|
||||||
do{
|
do{
|
||||||
c = fgetc(hostsf);
|
b = fgetc(hostsf);
|
||||||
if (c != EOF)
|
c = (char)b;
|
||||||
|
if (b != EOF)
|
||||||
strncat(buff, &c, 1);
|
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){
|
if(strncmp(buff,"# rhosts", 8) != 0){
|
||||||
fputs(buff, tmpf);
|
fputs(buff, tmpf);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
c = EOF;
|
b = EOF;
|
||||||
buff[0] = '\0';
|
buff[0] = '\0';
|
||||||
}while(c !=EOF);
|
}while(b !=EOF);
|
||||||
|
|
||||||
fclose(hostsf);
|
fclose(hostsf);
|
||||||
fclose(tmpf);
|
fclose(tmpf);
|
||||||
|
|
@ -170,18 +174,20 @@ int clean_download(){
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
char c;
|
char c;
|
||||||
|
int b;
|
||||||
char buff[MAXSTRSIZE];
|
char buff[MAXSTRSIZE];
|
||||||
int buffsize=1;
|
int buffsize=1;
|
||||||
buff[0] = '\0';
|
buff[0] = '\0';
|
||||||
|
|
||||||
do{
|
do{
|
||||||
c = fgetc(tmpdf);
|
b = fgetc(tmpdf);
|
||||||
|
c = (char)b;
|
||||||
buffsize++;
|
buffsize++;
|
||||||
if (buffsize > MAXSTRSIZE){
|
if (buffsize > MAXSTRSIZE){
|
||||||
printf("String too long when cleaning download: %s\n",buff);
|
printf("String too long when cleaning download: %s\n",buff);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (c!=EOF) // Later needs to check for NULL
|
if (b!=EOF) // Later needs to check for NULL
|
||||||
strncat(buff,&c,1);
|
strncat(buff,&c,1);
|
||||||
if (buffsize==2){
|
if (buffsize==2){
|
||||||
if (buff[0]=='#' || buff[0]=='\n'){
|
if (buff[0]=='#' || buff[0]=='\n'){
|
||||||
|
|
@ -190,12 +196,12 @@ int clean_download(){
|
||||||
buffsize=1;
|
buffsize=1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (c == '\n' || c == EOF){
|
if (c == '\n' || b == EOF){
|
||||||
fputs(buff,tmpf);
|
fputs(buff,tmpf);
|
||||||
buff[0]='\0';
|
buff[0]='\0';
|
||||||
buffsize=1;
|
buffsize=1;
|
||||||
}
|
}
|
||||||
}while (c!=EOF);
|
}while (b!=EOF);
|
||||||
fflush(tmpf);
|
fflush(tmpf);
|
||||||
fclose(tmpf);
|
fclose(tmpf);
|
||||||
fclose(tmpdf);
|
fclose(tmpdf);
|
||||||
|
|
@ -203,8 +209,10 @@ int clean_download(){
|
||||||
}
|
}
|
||||||
int skip_to_next_line(FILE **fp){
|
int skip_to_next_line(FILE **fp){
|
||||||
char c;
|
char c;
|
||||||
|
int b;
|
||||||
do{
|
do{
|
||||||
c = fgetc(*fp);
|
b = fgetc(*fp);
|
||||||
}while(c != '\n' && c != EOF);
|
c = (char)b;
|
||||||
|
}while(c != '\n' && b != EOF);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
26
src/rhosts.c
26
src/rhosts.c
|
|
@ -70,17 +70,19 @@ int parse_config(struct entry **entries){
|
||||||
j = &(*entries)[0].entrytype;
|
j = &(*entries)[0].entrytype;
|
||||||
|
|
||||||
char c='\0';
|
char c='\0';
|
||||||
|
int b=0;
|
||||||
char buff[MAXSTRSIZE];
|
char buff[MAXSTRSIZE];
|
||||||
buff[0]='\0';
|
buff[0]='\0';
|
||||||
short int valtyp = CONTENTTYPE_BLANK;
|
short int valtyp = CONTENTTYPE_BLANK;
|
||||||
|
|
||||||
// Loop through config file
|
// Loop through config file
|
||||||
do{
|
do{
|
||||||
c = fgetc(configfile);
|
b = fgetc(configfile);
|
||||||
|
c = (char)b;
|
||||||
// Detect if a comment
|
// Detect if a comment
|
||||||
if (strncmp(buff, "#",(long unsigned int)1) == 0 && \
|
if (strncmp(buff, "#",(long unsigned int)1) == 0 && \
|
||||||
valtyp == CONTENTTYPE_BLANK){
|
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
|
// Detect end of value type string
|
||||||
if (c == '=' && valtyp == CONTENTTYPE_BLANK){
|
if (c == '=' && valtyp == CONTENTTYPE_BLANK){
|
||||||
|
|
@ -92,7 +94,7 @@ int parse_config(struct entry **entries){
|
||||||
}
|
}
|
||||||
|
|
||||||
// Detect end of entry
|
// Detect end of entry
|
||||||
else if ((c == '\n' || c == EOF) \
|
else if ((c == '\n' || b == EOF) \
|
||||||
&& valtyp != CONTENTTYPE_BLANK){
|
&& valtyp != CONTENTTYPE_BLANK){
|
||||||
(*entries)[0].entrytype++;
|
(*entries)[0].entrytype++;
|
||||||
*entries = (struct entry *)realloc(*entries,\
|
*entries = (struct entry *)realloc(*entries,\
|
||||||
|
|
@ -104,13 +106,13 @@ int parse_config(struct entry **entries){
|
||||||
buff[0] = '\0';
|
buff[0] = '\0';
|
||||||
valtyp = CONTENTTYPE_BLANK;
|
valtyp = CONTENTTYPE_BLANK;
|
||||||
}
|
}
|
||||||
else if (c == '\n' || c == EOF){
|
else if (c == '\n' || b == EOF){
|
||||||
buff[0] = '\0';
|
buff[0] = '\0';
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
strncat(buff, &c, 1);
|
strncat(buff, &c, 1);
|
||||||
}
|
}
|
||||||
}while (c != EOF);
|
}while (b != EOF);
|
||||||
|
|
||||||
rc = fclose(configfile);
|
rc = fclose(configfile);
|
||||||
if (rc != 0){return 1;}
|
if (rc != 0){return 1;}
|
||||||
|
|
@ -134,13 +136,15 @@ int preserve_static_entries(){
|
||||||
}
|
}
|
||||||
char buff[MAXSTRSIZE];
|
char buff[MAXSTRSIZE];
|
||||||
char c = EOF;
|
char c = EOF;
|
||||||
|
int b = 0;
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
|
|
||||||
printf("Static hosts are:\n");
|
printf("Static hosts are:\n");
|
||||||
do{
|
do{
|
||||||
c = fgetc(hostsf);
|
b = fgetc(hostsf);
|
||||||
|
c = (char)b;
|
||||||
strncat(buff, &c, 1);
|
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'){
|
if (c == '\n'){
|
||||||
rc = fputs(buff, tmpf);
|
rc = fputs(buff, tmpf);
|
||||||
if (rc == EOF){
|
if (rc == EOF){
|
||||||
|
|
@ -151,7 +155,7 @@ int preserve_static_entries(){
|
||||||
printf("%s",buff);
|
printf("%s",buff);
|
||||||
buff[0] = '\0';
|
buff[0] = '\0';
|
||||||
}
|
}
|
||||||
}while ( c != EOF);
|
}while ( b != EOF);
|
||||||
rc = fputs("# rhosts begin\n", tmpf);
|
rc = fputs("# rhosts begin\n", tmpf);
|
||||||
if (rc == EOF){
|
if (rc == EOF){
|
||||||
fclose(hostsf);
|
fclose(hostsf);
|
||||||
|
|
@ -212,10 +216,10 @@ int copy_tmp_to_hosts(){
|
||||||
fclose(tmpf);
|
fclose(tmpf);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
char c;
|
int b;
|
||||||
|
|
||||||
for(c = fgetc(tmpf);c != EOF;c = fgetc(tmpf)){
|
for(b = fgetc(tmpf);b != EOF;b = fgetc(tmpf)){
|
||||||
fputc(c,hostsf);
|
fputc((char)b,hostsf);
|
||||||
}
|
}
|
||||||
remove(TMPLOCATION);
|
remove(TMPLOCATION);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue