[svn] GnuPG - r3870 - trunk/g10

svn author dshaw cvs at cvs.gnupg.org
Sun Aug 21 16:20:33 CEST 2005


Author: dshaw
Date: 2005-08-21 16:20:27 +0200 (Sun, 21 Aug 2005)
New Revision: 3870

Modified:
   trunk/g10/ChangeLog
   trunk/g10/exec.c
   trunk/g10/exec.h
Log:
* exec.h, exec.c (make_tempdir, expand_args, exec_write, exec_read):
Minor cleanup to use bitfield flags instead of a bunch of integers.


Modified: trunk/g10/ChangeLog
===================================================================
--- trunk/g10/ChangeLog	2005-08-20 19:38:45 UTC (rev 3869)
+++ trunk/g10/ChangeLog	2005-08-21 14:20:27 UTC (rev 3870)
@@ -1,3 +1,9 @@
+2005-08-21  David Shaw  <dshaw at jabberwocky.com>
+
+	* exec.h, exec.c (make_tempdir, expand_args, exec_write,
+	exec_read): Minor cleanup to use bitfield flags instead of a bunch
+	of integers.
+
 2005-08-20  David Shaw  <dshaw at jabberwocky.com>
 
 	* g10.c (main): Add aliases sign-with->local-user and

Modified: trunk/g10/exec.c
===================================================================
--- trunk/g10/exec.c	2005-08-20 19:38:45 UTC (rev 3869)
+++ trunk/g10/exec.c	2005-08-21 14:20:27 UTC (rev 3870)
@@ -120,9 +120,9 @@
   char *tmp=opt.temp_dir,*namein=info->name,*nameout;
 
   if(!namein)
-    namein=info->binary?"tempin" EXTSEP_S "bin":"tempin" EXTSEP_S "txt";
+    namein=info->flags.binary?"tempin" EXTSEP_S "bin":"tempin" EXTSEP_S "txt";
 
-  nameout=info->binary?"tempout" EXTSEP_S "bin":"tempout" EXTSEP_S "txt";
+  nameout=info->flags.binary?"tempout" EXTSEP_S "bin":"tempout" EXTSEP_S "txt";
 
   /* Make up the temp dir and files in case we need them */
 
@@ -174,13 +174,13 @@
 	      info->tempdir,strerror(errno));
   else
     {
-      info->madedir=1;
+      info->flags.madedir=1;
 
       info->tempfile_in=xmalloc(strlen(info->tempdir)+
 				strlen(DIRSEP_S)+strlen(namein)+1);
       sprintf(info->tempfile_in,"%s" DIRSEP_S "%s",info->tempdir,namein);
 
-      if(!info->writeonly)
+      if(!info->flags.writeonly)
 	{
 	  info->tempfile_out=xmalloc(strlen(info->tempdir)+
 				     strlen(DIRSEP_S)+strlen(nameout)+1);
@@ -188,7 +188,7 @@
 	}
     }
 
-  return info->madedir?0:G10ERR_GENERAL;
+  return info->flags.madedir?0:G10ERR_GENERAL;
 }
 
 /* Expands %i and %o in the args to the full temp files within the
@@ -198,8 +198,8 @@
   const char *ch=args_in;
   unsigned int size,len;
 
-  info->use_temp_files=0;
-  info->keep_temp_files=0;
+  info->flags.use_temp_files=0;
+  info->flags.keep_temp_files=0;
 
   if(DBG_EXTPROG)
     log_debug("expanding string \"%s\"\n",args_in);
@@ -220,31 +220,31 @@
 	  switch(*ch)
 	    {
 	    case 'O':
-	      info->keep_temp_files=1;
+	      info->flags.keep_temp_files=1;
 	      /* fall through */
 
 	    case 'o': /* out */
-	      if(!info->madedir)
+	      if(!info->flags.madedir)
 		{
 		  if(make_tempdir(info))
 		    goto fail;
 		}
 	      append=info->tempfile_out;
-	      info->use_temp_files=1;
+	      info->flags.use_temp_files=1;
 	      break;
 
 	    case 'I':
-	      info->keep_temp_files=1;
+	      info->flags.keep_temp_files=1;
 	      /* fall through */
 
 	    case 'i': /* in */
-	      if(!info->madedir)
+	      if(!info->flags.madedir)
 		{
 		  if(make_tempdir(info))
 		    goto fail;
 		}
 	      append=info->tempfile_in;
-	      info->use_temp_files=1;
+	      info->flags.use_temp_files=1;
 	      break;
 
 	    case '%':
@@ -285,8 +285,8 @@
     }
 
   if(DBG_EXTPROG)
-    log_debug("args expanded to \"%s\", use %d, keep %d\n",
-	      info->command,info->use_temp_files,info->keep_temp_files);
+    log_debug("args expanded to \"%s\", use %u, keep %u\n",info->command,
+	      info->flags.use_temp_files,info->flags.keep_temp_files);
 
   return 0;
 
@@ -331,15 +331,15 @@
 
   if(name)
     (*info)->name=xstrdup(name);
-  (*info)->binary=binary;
-  (*info)->writeonly=writeonly;
+  (*info)->flags.binary=binary;
+  (*info)->flags.writeonly=writeonly;
 
   /* Expand the args, if any */
   if(args_in && expand_args(*info,args_in))
     goto fail;
 
 #ifdef EXEC_TEMPFILE_ONLY
-  if(!(*info)->use_temp_files)
+  if(!(*info)->flags.use_temp_files)
     {
       log_error(_("this platform requires temporary files when calling"
 		  " external programs\n"));
@@ -350,7 +350,7 @@
 
   /* If there are no args, or there are args, but no temp files, we
      can use fork/exec/pipe */
-  if(args_in==NULL || (*info)->use_temp_files==0)
+  if(args_in==NULL || (*info)->flags.use_temp_files==0)
     {
       int to[2],from[2];
 
@@ -384,7 +384,7 @@
 
 	  /* If the program isn't going to respond back, they get to
              keep their stdout/stderr */
-	  if(!(*info)->writeonly)
+	  if(!(*info)->flags.writeonly)
 	    {
 	      /* implied close of STDERR */
 	      if(dup2(STDOUT_FILENO,STDERR_FILENO)==-1)
@@ -494,7 +494,7 @@
   fclose(info->tochild);
   info->tochild=NULL;
 
-  if(info->use_temp_files)
+  if(info->flags.use_temp_files)
     {
       if(DBG_EXTPROG)
 	log_debug("system() command is %s\n",info->command);
@@ -537,7 +537,7 @@
 	  goto fail;
 	}
 
-      if(!info->writeonly)
+      if(!info->flags.writeonly)
 	{
 	  info->fromchild=iobuf_open(info->tempfile_out);
           if (info->fromchild
@@ -590,7 +590,7 @@
     }
 #endif
 
-  if(info->madedir && !info->keep_temp_files)
+  if(info->flags.madedir && !info->flags.keep_temp_files)
     {
       if(info->tempfile_in)
 	{

Modified: trunk/g10/exec.h
===================================================================
--- trunk/g10/exec.h	2005-08-20 19:38:45 UTC (rev 3869)
+++ trunk/g10/exec.h	2005-08-21 14:20:27 UTC (rev 3870)
@@ -28,7 +28,15 @@
 
 struct exec_info
 {
-  int progreturn,binary,writeonly,madedir,use_temp_files,keep_temp_files;
+  int progreturn;
+  struct
+  {
+    unsigned int binary:1;
+    unsigned int writeonly:1;
+    unsigned int madedir:1;
+    unsigned int use_temp_files:1;
+    unsigned int keep_temp_files:1;
+  } flags;
   pid_t child;
   FILE *tochild;
   IOBUF fromchild;




More information about the Gnupg-commits mailing list