fgetsは改行記号'n'を自動的に捨てないこの関数に穴をあけた

1322 ワード

   :
   char *Is_ip6Get(char *is_ip6, char *hostname){
	FILE *fp = NULL;
	char temp[512];
	char path[1024];
	sprintf(path, "%s%s", IS_IP6, hostname);

	if (access(path, F_OK)) return NULL;

	if (NULL == (fp = fopen(path, "r"))) return NULL;

	if (fp){
		fgets(temp, 1024, fp);
		is_ip6 = temp;
	}
	return is_ip6;
}
          js :
     if(IPv6)
	 printf("var IPv6=\"%s\";
", IPv6); else printf("var IPv6=\"\";
"); : var IPv6=“1314 ”; : fgets
: char *Is_ip6Get(char *is_ip6, char *hostname){ FILE *fp = NULL; char temp[512]; char path[1024]; int len = 0; sprintf(path, "%s%s", IS_IP6, hostname); if (access(path, F_OK)) return NULL; if (NULL == (fp = fopen(path, "r"))) return NULL; if (fp){ fgets(temp, 1024, fp); if(!(strncmp(temp, "(null)", 6))) return NULL; len = strlen(temp); temp[len - 1] = '\0'; is_ip6 = temp; } return is_ip6; }