Return-Path: Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: (qmail 44880 invoked from network); 21 Aug 2009 15:39:39 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 21 Aug 2009 15:39:39 -0000 Received: (qmail 37492 invoked by uid 500); 21 Aug 2009 15:40:00 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 37334 invoked by uid 500); 21 Aug 2009 15:40:00 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 37318 invoked by uid 99); 21 Aug 2009 15:40:00 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 21 Aug 2009 15:40:00 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 21 Aug 2009 15:39:51 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id C243323888EC; Fri, 21 Aug 2009 15:39:30 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r806605 - in /commons/sandbox/runtime/trunk/src/main/native: Makefile.in Makefile.msc.in include/acr_file.h include/acr_filemk.h include/acr_private.h os/unix/temps.c os/win32/temps.c shared/cmnfile.c shared/fco.c test/testsuite.c Date: Fri, 21 Aug 2009 15:39:30 -0000 To: commits@commons.apache.org From: mturk@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090821153930.C243323888EC@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: mturk Date: Fri Aug 21 15:39:29 2009 New Revision: 806605 URL: http://svn.apache.org/viewvc?rev=806605&view=rev Log: Add temp file and dir support Added: commons/sandbox/runtime/trunk/src/main/native/include/acr_filemk.h (with props) commons/sandbox/runtime/trunk/src/main/native/os/unix/temps.c (with props) commons/sandbox/runtime/trunk/src/main/native/os/win32/temps.c (with props) commons/sandbox/runtime/trunk/src/main/native/shared/cmnfile.c (with props) Modified: commons/sandbox/runtime/trunk/src/main/native/Makefile.in commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in commons/sandbox/runtime/trunk/src/main/native/include/acr_file.h commons/sandbox/runtime/trunk/src/main/native/include/acr_private.h commons/sandbox/runtime/trunk/src/main/native/shared/fco.c commons/sandbox/runtime/trunk/src/main/native/test/testsuite.c Modified: commons/sandbox/runtime/trunk/src/main/native/Makefile.in URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/Makefile.in?rev=806605&r1=806604&r2=806605&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/Makefile.in (original) +++ commons/sandbox/runtime/trunk/src/main/native/Makefile.in Fri Aug 21 15:39:29 2009 @@ -79,6 +79,7 @@ COMMON_OBJS=\ $(SRCDIR)/shared/buildmark.$(OBJ) \ $(SRCDIR)/shared/clazz.$(OBJ) \ + $(SRCDIR)/shared/cmnfile.$(OBJ) \ $(SRCDIR)/shared/constp.$(OBJ) \ $(SRCDIR)/shared/descriptor.$(OBJ) \ $(SRCDIR)/shared/db.$(OBJ) \ @@ -117,6 +118,7 @@ $(SRCDIR)/os/unix/pshm.$(OBJ) \ $(SRCDIR)/os/unix/signals.$(OBJ) \ $(SRCDIR)/os/unix/syslog.$(OBJ) \ + $(SRCDIR)/os/unix/temps.$(OBJ) \ $(SRCDIR)/os/unix/time.$(OBJ) \ $(SRCDIR)/os/unix/uuid.$(OBJ) \ $(SRCDIR)/os/unix/uutils.$(OBJ) \ @@ -141,6 +143,7 @@ $(SRCDIR)/os/unix/pshm.$(OBJ) \ $(SRCDIR)/os/unix/signals.$(OBJ) \ $(SRCDIR)/os/unix/syslog.$(OBJ) \ + $(SRCDIR)/os/unix/temps.$(OBJ) \ $(SRCDIR)/os/unix/time.$(OBJ) \ $(SRCDIR)/os/unix/uuid.$(OBJ) \ $(SRCDIR)/os/unix/uutils.$(OBJ) \ @@ -162,6 +165,7 @@ $(SRCDIR)/os/unix/pshm.$(OBJ) \ $(SRCDIR)/os/unix/signals.$(OBJ) \ $(SRCDIR)/os/unix/syslog.$(OBJ) \ + $(SRCDIR)/os/unix/temps.$(OBJ) \ $(SRCDIR)/os/unix/time.$(OBJ) \ $(SRCDIR)/os/unix/uuid.$(OBJ) \ $(SRCDIR)/os/unix/uutils.$(OBJ) \ @@ -184,6 +188,7 @@ $(SRCDIR)/os/unix/psema.$(OBJ) \ $(SRCDIR)/os/unix/signals.$(OBJ) \ $(SRCDIR)/os/unix/syslog.$(OBJ) \ + $(SRCDIR)/os/unix/temps.$(OBJ) \ $(SRCDIR)/os/unix/time.$(OBJ) \ $(SRCDIR)/os/unix/uuid.$(OBJ) \ $(SRCDIR)/os/unix/uutils.$(OBJ) \ Modified: commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in?rev=806605&r1=806604&r2=806605&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in (original) +++ commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in Fri Aug 21 15:39:29 2009 @@ -70,6 +70,7 @@ COMMON_OBJS=\ $(SRCDIR)/shared/buildmark.$(OBJ) \ $(SRCDIR)/shared/clazz.$(OBJ) \ + $(SRCDIR)/shared/cmnfile.$(OBJ) \ $(SRCDIR)/shared/constp.$(OBJ) \ $(SRCDIR)/shared/descriptor.$(OBJ) \ $(SRCDIR)/shared/db.$(OBJ) \ @@ -112,6 +113,7 @@ $(SRCDIR)/os/win32/syslog.$(OBJ) \ $(SRCDIR)/os/win32/group.$(OBJ) \ $(SRCDIR)/os/win32/user.$(OBJ) \ + $(SRCDIR)/os/win32/temps.$(OBJ) \ $(SRCDIR)/os/win32/time.$(OBJ) \ $(SRCDIR)/os/win32/uuid.$(OBJ) \ $(SRCDIR)/os/win32/variant.$(OBJ) \ Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr_file.h URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr_file.h?rev=806605&r1=806604&r2=806605&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/include/acr_file.h (original) +++ commons/sandbox/runtime/trunk/src/main/native/include/acr_file.h Fri Aug 21 15:39:29 2009 @@ -130,6 +130,17 @@ file lock */ /** @} */ +typedef struct acr_file_t acr_file_t; + +struct acr_file_t { +#if defined (WIN32) + HANDLE fd; /* Os file descriptor */ +#else + int fd; +#endif + acr_pchar_t *name; /* Real file name */ + +}; /** Get FileType * @param env JNI environment to use. If NULL no exception will be thrown @@ -166,8 +177,15 @@ ACR_DECLARE(jobject) ACR_IoFileObjectCreate(JNIEnv *_E, const acr_pchar_t *fname, int ftype); +/** Get Filename from file descriptor. + * @param env JNI environment to use. + * @param fd File descriptor for which to get the name. + */ +ACR_DECLARE(const acr_pchar_t *) ACR_FileNameGet(JNIEnv *env, int fd); + #ifdef __cplusplus } #endif #endif /* _ACR_FILE_H */ + Added: commons/sandbox/runtime/trunk/src/main/native/include/acr_filemk.h URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr_filemk.h?rev=806605&view=auto ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/include/acr_filemk.h (added) +++ commons/sandbox/runtime/trunk/src/main/native/include/acr_filemk.h Fri Aug 21 15:39:29 2009 @@ -0,0 +1,69 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _ACR_FILEMK_H +#define _ACR_FILEMK_H + +#include "acr.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @file acr_filemk.h + * @brief + * + * ACR File make functions + * + */ + + +/** Create temporary unique file. + * @param env JNI environment to use. If NULL no exception will be thrown + * if stat fails. + * @pamap tmpath Path where to create the file. + * @param prefix File prefix. + * @param preserve Non zero to survive file close. + * @return File descriptor or -1 o failure. + */ +ACR_DECLARE(int) ACR_TempFileMake(JNIEnv *env, const acr_pchar_t *tmpath, + const acr_pchar_t *prefix, int preserve); + +/** Create temporary unique directory. + * @param env JNI environment to use. If NULL no exception will be thrown + * if stat fails. + * @pamap tmpath Path where to create the directory. + * @param prefix Directory prefix. + * @return Newly created unique directory path. Use ACR_Free when no longer + * needed. + */ +ACR_DECLARE(char *) ACR_TempDirMake(JNIEnv *env, const acr_pchar_t *tmpath, + const char *prefix); + +/** Get system temporary directory. + * @param env JNI environment to use. If NULL no exception will be thrown + * if temprary directory cannot be found. + * @return Temporary directory. + */ +ACR_DECLARE(const acr_pchar_t *) ACR_TempPathGet(JNIEnv *env); + +#ifdef __cplusplus +} +#endif + +#endif /* _ACR_FILEMK_H */ + Propchange: commons/sandbox/runtime/trunk/src/main/native/include/acr_filemk.h ------------------------------------------------------------------------------ svn:eol-style = native Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr_private.h URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr_private.h?rev=806605&r1=806604&r2=806605&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/include/acr_private.h (original) +++ commons/sandbox/runtime/trunk/src/main/native/include/acr_private.h Fri Aug 21 15:39:29 2009 @@ -289,6 +289,11 @@ #define I2P(P, T) ((T)LLT((jint)P)) #endif +/* Integer to void* casting + */ +#define I2V(I) ((void *)(ptrdiff_t)(I)) +#define V2I(P) ((int)(ptrdiff_t)(P)) + #define IS_JOBJECT_NULL(E, O) \ (!(O) || ((*(E))->IsSameObject((E), (O), NULL) == JNI_TRUE)) Added: commons/sandbox/runtime/trunk/src/main/native/os/unix/temps.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/temps.c?rev=806605&view=auto ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/os/unix/temps.c (added) +++ commons/sandbox/runtime/trunk/src/main/native/os/unix/temps.c Fri Aug 21 15:39:29 2009 @@ -0,0 +1,198 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "acr.h" +#include "acr_private.h" +#include "acr_arch.h" +#include "acr_error.h" +#include "acr_string.h" +#include "acr_memory.h" +#include "acr_descriptor.h" +#include "acr_env.h" +#include "acr_file.h" +#include "acr_filemk.h" + +static const char *_try_dirs[] = { + "/tmp", + "/usr/tmp", + "/var/tmp", + NULL +}; + +static const char *_try_envs[] = { + "TMP", + "TEMP", + "TMPDIR", + "TEMPDIR", + NULL +}; + +static int tmp_file_cleanup(void *file, int type, unsigned int flags) +{ + int rc = ACR_EBADF; + acr_file_t *fp = (acr_file_t *)file; + + if (type != ACR_DT_FILE) { + return ACR_EBADF; + } + if (fp->fd > 0) { + if (close(fp->fd)) + rc = ACR_GET_OS_ERROR(); + else + rc = ACR_SUCCESS; + } + x_free(fp->name); + free(fp); + return rc; +} + +ACR_DECLARE(int) ACR_TempFileMake(JNIEnv *_E, const char *tmpath, + const char *prefix, int preserve) +{ + int rc; + int fd; + char name[PATH_MAX] = ""; + acr_file_t *fp; + + if (tmpath) { + strlcpy(name, tmpath, PATH_MAX); + strlcat(name, "/", PATH_MAX); + } + strlcat(name, prefix, PATH_MAX); + strlcat(name, "XXXXXX", PATH_MAX); + + fd = mkstemp(name); + if (fd < 0) { + ACR_THROW_IO_ERRNO(); + return -1; + } + if (preserve) { + /* Set close on exec flag */ + int flags; + if ((flags = fcntl(fd, F_GETFD)) < 0) { + ACR_THROW_IO_ERRNO(); + return -1; + } + flags |= FD_CLOEXEC; + if (fcntl(fd, F_SETFD, flags) < 0) { + ACR_THROW_IO_ERRNO(); + return -1; + } + } + else + unlink(name); + fp = ACR_Calloc(_E, THROW_NMARK, sizeof(acr_file_t)); + if (!fp) { + rc = ACR_GET_OS_ERROR(); + if (preserve) + unlink(name); + close(fd); + ACR_THROW_IO_IF_ERR(rc); + return -1; + } + fp->fd = fd; + fp->name = ACR_StrdupA(_E, THROW_NMARK, name); + rc = acr_ioh_open(fp, ACR_DT_FILE, 0, tmp_file_cleanup); + return rc; +} + +ACR_DECLARE(char *) ACR_TempDirMake(JNIEnv *_E, const char *tmpath, + const char *prefix) +{ + int fd; + char name[PATH_MAX] = ""; + + for (;;) { + if (tmpath) { + strlcpy(name, tmpath, PATH_MAX); + strlcat(name, "/", PATH_MAX); + } + strlcat(name, prefix, PATH_MAX); + strlcat(name, "XXXXXX", PATH_MAX); + + fd = mkstemp(name); + if (fd < 0) { + ACR_THROW_IO_ERRNO(); + return NULL; + } + unlink(name); + close(fd); + /* Now try to make a directory with the same name. + * Use 0700 since mkstemp uses 0600. + */ + if (mkdir(name, 0700)) { + if (errno != EEXIST) { + ACR_THROW_IO_ERRNO(); + return NULL; + } + } + else + break; + } + return ACR_StrdupA(_E, THROW_NMARK, name); +} + +static int _temp_test(const char *path) +{ + char tp[PATH_MAX]; + int f; + strlcpy(tp, path, PATH_MAX); + strlcat(tp, "/.acrXXXXXX", PATH_MAX); + f = mkstemp(tp); + if (f > 0) { + unlink(tp); + close(f); + return 1; + } + else + return 0; +} + +ACR_DECLARE(const char *) ACR_TempPathGet(JNIEnv *_E) +{ + static char _temp_path[PATH_MAX] = ""; + int i = 0; + + if (_temp_path[0]) + return _temp_path; + while (_try_envs[i]) { + char *val = ACR_EnvGet(_try_envs[i]); + if (val && *val) { + if (_temp_test(val)) { + strlcpy(_temp_path, val, PATH_MAX); + break; + } + } + i++; + } + if (_temp_path[0]) + return _temp_path; + i = 0; + while (_try_dirs[i]) { + if (_temp_test(_try_dirs[i])) { + strlcpy(_temp_path, _try_dirs[i], PATH_MAX); + break; + } + i++; + } + + if (_temp_path[0]) { + return _temp_path; + } + else + return NULL; +} + Propchange: commons/sandbox/runtime/trunk/src/main/native/os/unix/temps.c ------------------------------------------------------------------------------ svn:eol-style = native Added: commons/sandbox/runtime/trunk/src/main/native/os/win32/temps.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/temps.c?rev=806605&view=auto ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/os/win32/temps.c (added) +++ commons/sandbox/runtime/trunk/src/main/native/os/win32/temps.c Fri Aug 21 15:39:29 2009 @@ -0,0 +1,62 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "acr.h" +#include "acr_private.h" +#include "acr_arch.h" +#include "acr_error.h" +#include "acr_string.h" +#include "acr_memory.h" +#include "acr_descriptor.h" +#include "acr_env.h" +#include "acr_file.h" +#include "acr_filemk.h" + +static int tmp_file_cleanup(void *file, int type, unsigned int flags) +{ + acr_file_t *fp = (acr_file_t *)file; + + if (type != ACR_DT_FILE) { + return ACR_EBADF; + } + if (IS_VALID_HANDLE(fp->fd)) { + if (!CloseHandle(fp->fd)) + return ACR_GET_OS_ERROR(); + else + return ACR_SUCCESS; + } + else + return ACR_EBADF; +} + +ACR_DECLARE(int) ACR_TempFileMake(JNIEnv *_E, const wchar_t *tmpath, + const wchar_t *prefix, int preserve, + wchar_t **filename) +{ + return -1; +} + +ACR_DECLARE(char *) ACR_TempDirMake(JNIEnv *_E, const wchar_t *tmpath, + const wchar_t *prefix) +{ + return NULL; +} + +ACR_DECLARE(const wchar_t *) ACR_TempPathGet(JNIEnv *_E) +{ + return NULL; +} + Propchange: commons/sandbox/runtime/trunk/src/main/native/os/win32/temps.c ------------------------------------------------------------------------------ svn:eol-style = native Added: commons/sandbox/runtime/trunk/src/main/native/shared/cmnfile.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/cmnfile.c?rev=806605&view=auto ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/shared/cmnfile.c (added) +++ commons/sandbox/runtime/trunk/src/main/native/shared/cmnfile.c Fri Aug 21 15:39:29 2009 @@ -0,0 +1,45 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * + * @author Mladen Turk + */ + +#include "acr.h" +#include "acr_private.h" +#include "acr_arch.h" +#include "acr_error.h" +#include "acr_string.h" +#include "acr_descriptor.h" +#include "acr_file.h" +#include "acr_filemk.h" + +/** + * Common File functions + */ + +ACR_DECLARE(const acr_pchar_t *) ACR_FileNameGet(JNIEnv *_E, int fd) +{ + acr_file_t *fp = (acr_file_t *)ACR_IOH(fd); + + if (IS_INVALID_HANDLE(fp) || ACR_IOH_TYPE(fd) != ACR_DT_FILE) { + ACR_THROW_IO_IF_ERR(ACR_EBADF); + return NULL; + } + return fp->name; +} + Propchange: commons/sandbox/runtime/trunk/src/main/native/shared/cmnfile.c ------------------------------------------------------------------------------ svn:eol-style = native Modified: commons/sandbox/runtime/trunk/src/main/native/shared/fco.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/fco.c?rev=806605&r1=806604&r2=806605&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/shared/fco.c (original) +++ commons/sandbox/runtime/trunk/src/main/native/shared/fco.c Fri Aug 21 15:39:29 2009 @@ -25,6 +25,7 @@ #include "acr_string.h" #include "acr_clazz.h" #include "acr_file.h" +#include "acr_filemk.h" /** * Common File object Modified: commons/sandbox/runtime/trunk/src/main/native/test/testsuite.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/test/testsuite.c?rev=806605&r1=806604&r2=806605&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/test/testsuite.c (original) +++ commons/sandbox/runtime/trunk/src/main/native/test/testsuite.c Fri Aug 21 15:39:29 2009 @@ -29,6 +29,7 @@ #include "acr_pointer.h" #include "acr_descriptor.h" #include "acr_file.h" +#include "acr_filemk.h" #include "acr_xdr.h" #include "acr_shm.h" #include "acr_crypto.h" @@ -88,6 +89,49 @@ return 0; } +static int test_mktemp(int argc, const char *const argv[]) +{ + int failed = 0; + int fd; + char *fn; + fprintf(stdout, "Using Temporary Directory : `%s\'\n", + ACR_TempPathGet(NULL)); + + fd = ACR_TempFileMake(NULL, ACR_TempPathGet(NULL), + "acr-test-", 0); + if (fd < 0) + failed++; + else { + fprintf(stdout, "Using Temporary File : `%s\'\n", + ACR_FileNameGet(NULL, fd)); + } + + fd = ACR_TempFileMake(NULL, ACR_TempPathGet(NULL), + "acr-test-", 1); + if (fd < 0) + failed++; + else { + fprintf(stdout, "Using Temporary File : `%s\'\n", + ACR_FileNameGet(NULL, fd)); + } + fn = ACR_TempDirMake(NULL, ACR_TempPathGet(NULL), + "acr-test-"); + if (fn == NULL) + failed++; + else { + fprintf(stdout, "Using Temporary Dir : `%s\'\n", fn); + ACR_Free(NULL, THROW_NMARK, fn); + } + + tests_failed += failed; + if (failed) + fprintf(stderr, "mktemp: Failed (%d)\n", failed); + else + fprintf(stdout, "mktemp: OK\n"); + + return 0; +} + int main(int argc, const char *const argv[]) { int rv = 0; @@ -138,6 +182,9 @@ else if (!strcasecmp(run_test, "getenv")) { rv = test_getenv(argc, argv); } + else if (!strcasecmp(run_test, "mktemp")) { + rv = test_mktemp(argc, argv); + } } cleanup: