summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaiki Ueno <ueno@gnu.org>2020-05-30 11:06:57 +0200
committerDaiki Ueno <ueno@gnu.org>2020-05-30 11:10:12 +0200
commit14e2203ce5d7a6bbe050861a1206873a040674e3 (patch)
tree11e6dc0698f3d4840dc01c2c537064acf79ad685 /src
parent1976600876a3f0724b52c61d96998560dc4c0acb (diff)
downloadgnutls-14e2203ce5d7a6bbe050861a1206873a040674e3.tar.gz
build: write "FILE *fp" instead of "FILE *fd"tmp-fileio
This makes it clear that "fd" is not a file descriptor but a FILE pointer. Suggested by Tim Rühsen. Signed-off-by: Daiki Ueno <ueno@gnu.org>
Diffstat (limited to 'src')
-rw-r--r--src/certtool-common.c24
-rw-r--r--src/psk.c46
-rw-r--r--src/serv.c10
-rw-r--r--src/srptool.c98
4 files changed, 89 insertions, 89 deletions
diff --git a/src/certtool-common.c b/src/certtool-common.c
index ade6b1b569..3af2d08080 100644
--- a/src/certtool-common.c
+++ b/src/certtool-common.c
@@ -389,7 +389,7 @@ gnutls_x509_crt_t load_cert(int mand, common_info_st * info)
gnutls_x509_crt_t *load_cert_list(int mand, size_t * crt_size,
common_info_st * info)
{
- FILE *fd;
+ FILE *fp;
static gnutls_x509_crt_t *crt;
int ret;
gnutls_datum_t dat;
@@ -409,18 +409,18 @@ gnutls_x509_crt_t *load_cert_list(int mand, size_t * crt_size,
return NULL;
}
- fd = fopen(info->cert, "r");
- if (fd == NULL) {
+ fp = fopen(info->cert, "r");
+ if (fp == NULL) {
fprintf(stderr, "Could not open %s\n", info->cert);
app_exit(1);
}
- fix_lbuffer(file_size(fd));
+ fix_lbuffer(file_size(fp));
- size = fread(lbuffer, 1, lbuffer_size - 1, fd);
+ size = fread(lbuffer, 1, lbuffer_size - 1, fp);
lbuffer[size] = 0;
- fclose(fd);
+ fclose(fp);
dat.data = (void *) lbuffer;
dat.size = size;
@@ -448,7 +448,7 @@ gnutls_x509_crt_t *load_cert_list(int mand, size_t * crt_size,
gnutls_x509_crl_t *load_crl_list(int mand, size_t * crl_size,
common_info_st * info)
{
- FILE *fd;
+ FILE *fp;
static gnutls_x509_crl_t *crl;
unsigned int crl_max;
int ret;
@@ -467,18 +467,18 @@ gnutls_x509_crl_t *load_crl_list(int mand, size_t * crl_size,
return NULL;
}
- fd = fopen(info->crl, "r");
- if (fd == NULL) {
+ fp = fopen(info->crl, "r");
+ if (fp == NULL) {
fprintf(stderr, "Could not open %s\n", info->crl);
app_exit(1);
}
- fix_lbuffer(file_size(fd));
+ fix_lbuffer(file_size(fp));
- size = fread(lbuffer, 1, lbuffer_size - 1, fd);
+ size = fread(lbuffer, 1, lbuffer_size - 1, fp);
lbuffer[size] = 0;
- fclose(fd);
+ fclose(fp);
dat.data = (void *) lbuffer;
dat.size = size;
diff --git a/src/psk.c b/src/psk.c
index 775d8f80c9..6f77c6f285 100644
--- a/src/psk.c
+++ b/src/psk.c
@@ -141,35 +141,35 @@ int main(int argc, char **argv)
static int filecopy(const char *src, const char *dst)
{
- FILE *fd, *fd2;
+ FILE *fp, *fp2;
char line[5 * 1024];
char *p;
- fd = fopen(dst, "w");
- if (fd == NULL) {
+ fp = fopen(dst, "w");
+ if (fp == NULL) {
fprintf(stderr, "Cannot open '%s' for write\n", dst);
return -1;
}
- fd2 = fopen(src, "r");
- if (fd2 == NULL) {
+ fp2 = fopen(src, "r");
+ if (fp2 == NULL) {
/* empty file */
- fclose(fd);
+ fclose(fp);
return 0;
}
line[sizeof(line) - 1] = 0;
do {
- p = fgets(line, sizeof(line) - 1, fd2);
+ p = fgets(line, sizeof(line) - 1, fp2);
if (p == NULL)
break;
- fputs(line, fd);
+ fputs(line, fp);
}
while (1);
- fclose(fd);
- fclose(fd2);
+ fclose(fp);
+ fclose(fp2);
return 0;
}
@@ -178,7 +178,7 @@ static int
write_key(const char *username, const char *key, int key_size,
const char *passwd_file)
{
- FILE *fd;
+ FILE *fp;
char line[5 * 1024];
char *p, *pp;
char tmpname[1024];
@@ -186,7 +186,7 @@ write_key(const char *username, const char *key, int key_size,
/* delete previous entry */
struct stat st;
- FILE *fd2;
+ FILE *fp2;
int put;
if (strlen(passwd_file) + 5 > sizeof(tmpname)) {
@@ -207,25 +207,25 @@ write_key(const char *username, const char *key, int key_size,
return -1;
}
- fd = fopen(passwd_file, "w");
- if (fd == NULL) {
+ fp = fopen(passwd_file, "w");
+ if (fp == NULL) {
fprintf(stderr, "Cannot open '%s' for write\n",
passwd_file);
(void)remove(tmpname);
return -1;
}
- fd2 = fopen(tmpname, "r");
- if (fd2 == NULL) {
+ fp2 = fopen(tmpname, "r");
+ if (fp2 == NULL) {
fprintf(stderr, "Cannot open '%s' for read\n", tmpname);
(void)remove(tmpname);
- fclose(fd);
+ fclose(fp);
return -1;
}
put = 0;
do {
- p = fgets(line, sizeof(line) - 1, fd2);
+ p = fgets(line, sizeof(line) - 1, fp2);
if (p == NULL)
break;
@@ -237,19 +237,19 @@ write_key(const char *username, const char *key, int key_size,
MAX(strlen(username),
(unsigned int) (pp - p))) == 0) {
put = 1;
- fprintf(fd, "%s:%s\n", username, key);
+ fprintf(fp, "%s:%s\n", username, key);
} else {
- fputs(line, fd);
+ fputs(line, fp);
}
}
while (1);
if (put == 0) {
- fprintf(fd, "%s:%s\n", username, key);
+ fprintf(fp, "%s:%s\n", username, key);
}
- fclose(fd);
- fclose(fd2);
+ fclose(fp);
+ fclose(fp2);
(void)remove(tmpname);
diff --git a/src/serv.c b/src/serv.c
index 414cd0546b..57304bc9d3 100644
--- a/src/serv.c
+++ b/src/serv.c
@@ -219,7 +219,7 @@ static void read_dh_params(void)
char tmpdata[2048];
int size;
gnutls_datum_t params;
- FILE *fd;
+ FILE *fp;
if (gnutls_dh_params_init(&dh_params) < 0) {
fprintf(stderr, "Error in dh parameter initialization\n");
@@ -228,15 +228,15 @@ static void read_dh_params(void)
/* read the params file
*/
- fd = fopen(dh_params_file, "r");
- if (fd == NULL) {
+ fp = fopen(dh_params_file, "r");
+ if (fp == NULL) {
fprintf(stderr, "Could not open %s\n", dh_params_file);
exit(1);
}
- size = fread(tmpdata, 1, sizeof(tmpdata) - 1, fd);
+ size = fread(tmpdata, 1, sizeof(tmpdata) - 1, fp);
tmpdata[size] = 0;
- fclose(fd);
+ fclose(fp);
params.data = (unsigned char *) tmpdata;
params.size = size;
diff --git a/src/srptool.c b/src/srptool.c
index 27821be238..7939f6bfab 100644
--- a/src/srptool.c
+++ b/src/srptool.c
@@ -74,14 +74,14 @@ static void print_num(const char *msg, const gnutls_datum_t * num)
static int generate_create_conf(const char *tpasswd_conf)
{
- FILE *fd;
+ FILE *fp;
char line[5 * 1024];
int index = 1, srp_idx;
gnutls_datum_t g, n;
gnutls_datum_t str_g, str_n;
- fd = fopen(tpasswd_conf, "w");
- if (fd == NULL) {
+ fp = fopen(tpasswd_conf, "w");
+ if (fp == NULL) {
fprintf(stderr, "Cannot open file '%s'\n", tpasswd_conf);
return -1;
}
@@ -119,13 +119,13 @@ static int generate_create_conf(const char *tpasswd_conf)
if (gnutls_srp_base64_encode_alloc(&n, &str_n) < 0) {
fprintf(stderr, "Could not encode\n");
- fclose(fd);
+ fclose(fp);
return -1;
}
if (gnutls_srp_base64_encode_alloc(&g, &str_g) < 0) {
fprintf(stderr, "Could not encode\n");
- fclose(fd);
+ fclose(fp);
return -1;
}
@@ -134,11 +134,11 @@ static int generate_create_conf(const char *tpasswd_conf)
gnutls_free(str_n.data);
gnutls_free(str_g.data);
- fwrite(line, 1, strlen(line), fd);
+ fwrite(line, 1, strlen(line), fp);
}
- fclose(fd);
+ fclose(fp);
return 0;
@@ -211,35 +211,35 @@ _verify_passwd_int(const char *username, const char *passwd,
static int filecopy(const char *src, const char *dst)
{
- FILE *fd, *fd2;
+ FILE *fp, *fp2;
char line[5 * 1024];
char *p;
- fd = fopen(dst, "w");
- if (fd == NULL) {
+ fp = fopen(dst, "w");
+ if (fp == NULL) {
fprintf(stderr, "Cannot open '%s' for write\n", dst);
return -1;
}
- fd2 = fopen(src, "r");
- if (fd2 == NULL) {
+ fp2 = fopen(src, "r");
+ if (fp2 == NULL) {
/* empty file */
- fclose(fd);
+ fclose(fp);
return 0;
}
line[sizeof(line) - 1] = 0;
do {
- p = fgets(line, sizeof(line) - 1, fd2);
+ p = fgets(line, sizeof(line) - 1, fp2);
if (p == NULL)
break;
- fputs(line, fd);
+ fputs(line, fp);
}
while (1);
- fclose(fd);
- fclose(fd2);
+ fclose(fp);
+ fclose(fp2);
return 0;
}
@@ -247,18 +247,18 @@ static int filecopy(const char *src, const char *dst)
/* accepts password file */
static int find_strchr(const char *username, const char *file)
{
- FILE *fd;
+ FILE *fp;
char *pos;
char line[5 * 1024];
unsigned int i;
- fd = fopen(file, "r");
- if (fd == NULL) {
+ fp = fopen(file, "r");
+ if (fp == NULL) {
fprintf(stderr, "Cannot open file '%s'\n", file);
return -1;
}
- while (fgets(line, sizeof(line), fd) != NULL) {
+ while (fgets(line, sizeof(line), fp) != NULL) {
/* move to first ':' */
i = 0;
while ((line[i] != ':') && (line[i] != '\0')
@@ -269,12 +269,12 @@ static int find_strchr(const char *username, const char *file)
/* find the index */
pos = strrchr(line, ':');
pos++;
- fclose(fd);
+ fclose(fp);
return atoi(pos);
}
}
- fclose(fd);
+ fclose(fp);
return -1;
}
@@ -285,7 +285,7 @@ static int
verify_passwd(const char *conffile, const char *tpasswd,
const char *username, const char *passwd)
{
- FILE *fd;
+ FILE *fp;
char line[5 * 1024];
unsigned int i;
gnutls_datum_t g, n;
@@ -299,14 +299,14 @@ verify_passwd(const char *conffile, const char *tpasswd,
return -1;
}
- fd = fopen(conffile, "r");
- if (fd == NULL) {
+ fp = fopen(conffile, "r");
+ if (fp == NULL) {
fprintf(stderr, "Cannot find %s\n", conffile);
return -1;
}
do {
- p = fgets(line, sizeof(line) - 1, fd);
+ p = fgets(line, sizeof(line) - 1, fp);
}
while (p != NULL && atoi(p) != iindex);
@@ -316,20 +316,20 @@ verify_passwd(const char *conffile, const char *tpasswd,
}
line[sizeof(line) - 1] = 0;
- fclose(fd);
+ fclose(fp);
if ((iindex = read_conf_values(&g, &n, line)) < 0) {
fprintf(stderr, "Cannot parse conf file '%s'\n", conffile);
return -1;
}
- fd = fopen(tpasswd, "r");
- if (fd == NULL) {
+ fp = fopen(tpasswd, "r");
+ if (fp == NULL) {
fprintf(stderr, "Cannot open file '%s'\n", tpasswd);
return -1;
}
- while (fgets(line, sizeof(line), fd) != NULL) {
+ while (fgets(line, sizeof(line), fp) != NULL) {
/* move to first ':'
* This is the actual verifier.
*/
@@ -342,7 +342,7 @@ verify_passwd(const char *conffile, const char *tpasswd,
char *verifier_pos, *salt_pos;
pos = strchr(line, ':');
- fclose(fd);
+ fclose(fp);
if (pos == NULL) {
fprintf(stderr,
"Cannot parse conf file '%s'\n",
@@ -369,7 +369,7 @@ verify_passwd(const char *conffile, const char *tpasswd,
}
}
- fclose(fd);
+ fclose(fp);
return -1;
}
@@ -511,7 +511,7 @@ int
crypt_int(const char *username, const char *passwd, int salt_size,
const char *tpasswd_conf, const char *tpasswd, int uindex)
{
- FILE *fd;
+ FILE *fp;
char *cr;
gnutls_datum_t g, n;
char line[5 * 1024];
@@ -519,14 +519,14 @@ crypt_int(const char *username, const char *passwd, int salt_size,
int iindex;
char tmpname[1024];
- fd = fopen(tpasswd_conf, "r");
- if (fd == NULL) {
+ fp = fopen(tpasswd_conf, "r");
+ if (fp == NULL) {
fprintf(stderr, "Cannot find %s\n", tpasswd_conf);
return -1;
}
do { /* find the specified uindex in file */
- p = fgets(line, sizeof(line) - 1, fd);
+ p = fgets(line, sizeof(line) - 1, fp);
}
while (p != NULL && (iindex = atoi(p)) != uindex);
@@ -536,7 +536,7 @@ crypt_int(const char *username, const char *passwd, int salt_size,
}
line[sizeof(line) - 1] = 0;
- fclose(fd);
+ fclose(fp);
if ((iindex = read_conf_values(&g, &n, line)) < 0) {
fprintf(stderr, "Cannot parse conf file '%s'\n",
tpasswd_conf);
@@ -550,7 +550,7 @@ crypt_int(const char *username, const char *passwd, int salt_size,
} else {
/* delete previous entry */
struct stat st;
- FILE *fd2;
+ FILE *fp2;
int put;
if (strlen(tpasswd) + 5 > sizeof(tmpname)) {
@@ -572,16 +572,16 @@ crypt_int(const char *username, const char *passwd, int salt_size,
return -1;
}
- fd = fopen(tpasswd, "w");
- if (fd == NULL) {
+ fp = fopen(tpasswd, "w");
+ if (fp == NULL) {
fprintf(stderr, "Cannot open '%s' for write\n",
tpasswd);
(void)remove(tmpname);
return -1;
}
- fd2 = fopen(tmpname, "r");
- if (fd2 == NULL) {
+ fp2 = fopen(tmpname, "r");
+ if (fp2 == NULL) {
fprintf(stderr, "Cannot open '%s' for read\n",
tmpname);
(void)remove(tmpname);
@@ -590,7 +590,7 @@ crypt_int(const char *username, const char *passwd, int salt_size,
put = 0;
do {
- p = fgets(line, sizeof(line) - 1, fd2);
+ p = fgets(line, sizeof(line) - 1, fp2);
if (p == NULL)
break;
@@ -602,20 +602,20 @@ crypt_int(const char *username, const char *passwd, int salt_size,
MAX(strlen(username),
(unsigned int) (pp - p))) == 0) {
put = 1;
- fprintf(fd, "%s:%s:%u\n", username, cr,
+ fprintf(fp, "%s:%s:%u\n", username, cr,
iindex);
} else {
- fputs(line, fd);
+ fputs(line, fp);
}
}
while (1);
if (put == 0) {
- fprintf(fd, "%s:%s:%u\n", username, cr, iindex);
+ fprintf(fp, "%s:%s:%u\n", username, cr, iindex);
}
- fclose(fd);
- fclose(fd2);
+ fclose(fp);
+ fclose(fp2);
(void)remove(tmpname);