14887Schin /*********************************************************************** 24887Schin * * 34887Schin * This software is part of the ast package * 4*8462SApril.Chin@Sun.COM * Copyright (c) 1985-2008 AT&T Intellectual Property * 54887Schin * and is licensed under the * 64887Schin * Common Public License, Version 1.0 * 7*8462SApril.Chin@Sun.COM * by AT&T Intellectual Property * 84887Schin * * 94887Schin * A copy of the License is available at * 104887Schin * http://www.opensource.org/licenses/cpl1.0.txt * 114887Schin * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) * 124887Schin * * 134887Schin * Information and Software Systems Research * 144887Schin * AT&T Research * 154887Schin * Florham Park NJ * 164887Schin * * 174887Schin * Glenn Fowler <gsf@research.att.com> * 184887Schin * David Korn <dgk@research.att.com> * 194887Schin * Phong Vo <kpv@research.att.com> * 204887Schin * * 214887Schin ***********************************************************************/ 224887Schin #pragma prototyped 234887Schin /* 244887Schin * mktemp,mkstemp implementation 254887Schin */ 264887Schin 274887Schin #define mktemp ______mktemp 284887Schin #define mkstemp ______mkstemp 294887Schin 304887Schin #include <ast.h> 314887Schin #include <stdio.h> 324887Schin 334887Schin #undef mktemp 344887Schin #undef mkstemp 354887Schin 364887Schin #undef _def_map_ast 374887Schin #include <ast_map.h> 384887Schin 394887Schin #if defined(__EXPORT__) 404887Schin #define extern __EXPORT__ 414887Schin #endif 424887Schin 434887Schin static char* 444887Schin temp(char* buf, int* fdp) 454887Schin { 464887Schin char* s; 474887Schin char* d; 484887Schin int n; 494887Schin size_t len; 504887Schin 514887Schin len = strlen(buf); 524887Schin if (s = strrchr(buf, '/')) 534887Schin { 544887Schin *s++ = 0; 554887Schin d = buf; 564887Schin } 574887Schin else 584887Schin { 594887Schin s = buf; 604887Schin d = ""; 614887Schin } 624887Schin if ((n = strlen(s)) < 6 || strcmp(s + n - 6, "XXXXXX")) 634887Schin *buf = 0; 644887Schin else 654887Schin { 664887Schin *(s + n - 6) = 0; 674887Schin if (!pathtemp(buf, len, d, s, fdp)) 684887Schin *buf = 0; 694887Schin } 704887Schin return buf; 714887Schin } 724887Schin 734887Schin extern char* 744887Schin mktemp(char* buf) 754887Schin { 764887Schin return temp(buf, NiL); 774887Schin } 784887Schin 794887Schin extern int 804887Schin mkstemp(char* buf) 814887Schin { 824887Schin int fd; 834887Schin 844887Schin return *temp(buf, &fd) ? fd : -1; 854887Schin } 86