Collect spool-layout code to one file
[exim.git] / src / src / spool_in.c
index 6341387a206f45f6a91181548e26e1da3d0b2cb2..8e3099d8888bb262a4c7895d6b61ea8a679c80e9 100644 (file)
@@ -37,7 +37,6 @@ spool_open_datafile(uschar *id)
 int i;
 struct stat statbuf;
 flock_t lock_data;
-uschar spoolname[256];
 int fd;
 
 /* If split_spool_directory is set, first look for the file in the appropriate
@@ -49,13 +48,13 @@ splitting state. */
 
 for (i = 0; i < 2; i++)
   {
+  uschar * fname;
   int save_errno;
   message_subdir[0] = split_spool_directory == (i == 0) ? id[5] : 0;
-  snprintf(CS spoolname, sizeof(spoolname), "%s/input/%s/%s/%s-D",
-           spool_directory, queue_name, message_subdir, id);
-  DEBUG(D_deliver) debug_printf("Trying spool file %s\n", spoolname);
+  fname = spool_fname(US"input", message_subdir, id, US"-D");
+  DEBUG(D_deliver) debug_printf("Trying spool file %s\n", fname);
 
-  if ((fd = Uopen(spoolname, O_RDWR | O_APPEND, 0)) >= 0)
+  if ((fd = Uopen(fname, O_RDWR | O_APPEND, 0)) >= 0)
     break;
   save_errno = errno;
   if (errno == ENOENT)
@@ -64,7 +63,7 @@ for (i = 0; i < 2; i++)
     if (!queue_running)
       log_write(0, LOG_MAIN, "Spool file %s-D not found", id);
     }
-  else log_write(0, LOG_MAIN, "Spool error for %s: %s", spoolname,
+  else log_write(0, LOG_MAIN, "Spool error for %s: %s", fname,
     strerror(errno));
   errno = save_errno;
   return -1;
@@ -322,10 +321,11 @@ for (n = 0; n < 2; n++)
   {
   if (!subdir_set)
     message_subdir[0] = split_spool_directory == (n == 0) ? name[5] : 0;
-  sprintf(CS big_buffer, "%s/input/%s/%s/%s",
-         spool_directory, queue_name, message_subdir, name);
-  if ((f = Ufopen(big_buffer, "rb"))) break;
-  if (n != 0 || subdir_set || errno != ENOENT) return spool_read_notopen;
+
+  if ((f = Ufopen(spool_fname(US"input", message_subdir, name, US""), "rb")))
+    break;
+  if (n != 0 || subdir_set || errno != ENOENT)
+    return spool_read_notopen;
   }
 
 errno = 0;