diff options
Diffstat (limited to 'g10/mkdtemp.c')
-rw-r--r-- | g10/mkdtemp.c | 36 |
1 files changed, 24 insertions, 12 deletions
diff --git a/g10/mkdtemp.c b/g10/mkdtemp.c index 50a083005..0323486a3 100644 --- a/g10/mkdtemp.c +++ b/g10/mkdtemp.c @@ -1,3 +1,23 @@ +/* mkdtemp.c - libc replacement function + * Copyright (C) 2001 Free Software Foundation, Inc. + * + * This file is part of GnuPG. + * + * GnuPG is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GnuPG is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + /* This is a replacement function for mkdtemp in case the platform we're building on (like mine!) doesn't have it. */ @@ -23,29 +43,21 @@ char *mkdtemp(char *template) idx=strlen(template); - if(idx==0) - { - errno=EINVAL; - return NULL; - } - - ch=&template[idx-1]; - /* Walk backwards to count all the Xes */ - while(*ch=='X' && count<idx) + while(idx>0 && template[idx-1]=='X') { count++; - ch--; + idx--; } - ch++; - if(count==0) { errno=EINVAL; return NULL; } + ch=&template[idx]; + /* Try 4 times to make the temp directory */ for(attempts=0;attempts<4;attempts++) { |