chiark / gitweb /
privcache: uncached_get: Introduce `databuf' local
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 7 Dec 2019 14:02:49 +0000 (14:02 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 15 Feb 2020 21:56:54 +0000 (21:56 +0000)
This is a bit more convenient and will also make a future commit much
easier too read.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
privcache.c

index a5a67a520d36301bbc27d57485d14458de41987e..f95ee37a6600e0d2b280dc614652b7c31300ad93 100644 (file)
@@ -47,6 +47,7 @@ static struct sigprivkey_if *uncached_get(struct privcache *st,
 
     const char *path=st->path.buffer;
     struct hash_if *defhash=st->defhash;
+    struct buffer_if *databuf=&st->databuf;
 
     f = fopen(path,"rb");
     if (!f) {
@@ -61,8 +62,8 @@ static struct sigprivkey_if *uncached_get(struct privcache *st,
     }
 
     setbuf(f,0);
-    buffer_init(&st->databuf,0);
-    ssize_t got=fread(st->databuf.base,1,st->databuf.alloclen,f);
+    buffer_init(databuf,0);
+    ssize_t got=fread(databuf->base,1,databuf->alloclen,f);
     if (ferror(f)) {
        slilog(log,M_ERR,"failed to read private-key file %s",
               path);
@@ -70,7 +71,7 @@ static struct sigprivkey_if *uncached_get(struct privcache *st,
     }
     if (!feof(f)) {
        slilog(log,M_ERR,"private key file %s longer than max %d",
-              path, (int)st->databuf.alloclen);
+              path, (int)databuf->alloclen);
        goto out;
     }
     fclose(f); f=0;
@@ -88,10 +89,10 @@ static struct sigprivkey_if *uncached_get(struct privcache *st,
     goto out;
 
  found:
-    st->databuf.start=st->databuf.base;
-    st->databuf.size=got;
+    databuf->start=databuf->base;
+    databuf->size=got;
     struct cloc loc = { .file=path, .line=0 };
-    ok=scheme->loadpriv(scheme, &st->databuf, &sigpriv, log, loc);
+    ok=scheme->loadpriv(scheme, databuf, &sigpriv, log, loc);
     if (!ok) goto out; /* loadpriv will have logged */
 
     if (sigpriv->sethash) {