delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2014/01/13/16:36:13

X-Recipient: archive-cygwin AT delorie DOT com
DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:from:content-type:content-transfer-encoding
:subject:date:message-id:cc:to:mime-version; q=dns; s=default; b=
uP0EM8elFHMDyCkekUinNKKVLJDj7IigYqW7tPJ31lTPkDadVUgA2SCjY7vauXBX
mJEUPWnm7VuF4bMPBH0k3LHy6BVCTSJgJLPvpUa6/WVi68n/2XmuVt/pryM1byom
HMQ8BcV/XiWhe86r1EWguDDs5afIl9Xa4LRLLSu8l4o=
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:from:content-type:content-transfer-encoding
:subject:date:message-id:cc:to:mime-version; s=default; bh=Wc5Bh
bI7gi/FlGEGTYFDtqXjSek=; b=SaIWlH2eZdtfhvJ0q/BK0Ak+JMenmPD9tAkj5
MMqC/UrkZH2tzL2TsI0ZKF2zaNujVOWZveSnhC7nGCB0eFQV8zxdx1s7xY5muQ/B
QNrT53g1ArljiT1iILfUuWm4otaT/vbVrpaMbJinUjbyBsGEV8LcnReF9faT384k
LQrnxw=
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Authentication-Results: sourceware.org; auth=none
X-Virus-Found: No
X-Spam-SWARE-Status: No, score=-1.2 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2
X-HELO: mail-pb0-f47.google.com
X-Received: by 10.68.136.162 with SMTP id qb2mr32611207pbb.88.1389648955533; Mon, 13 Jan 2014 13:35:55 -0800 (PST)
From: Alex Reynolds <alexpreynolds AT gmail DOT com>
Subject: error: mkstemp was not declared in this scope
Date: Mon, 13 Jan 2014 13:32:20 -0800
Message-Id: <F9A2DD7F-D2D0-4F7D-9129-3A0805FC8DEF@gmail.com>
Cc: Alex Reynolds <alexpreynolds AT gmail DOT com>
To: cygwin AT cygwin DOT com
Mime-Version: 1.0 (Mac OS X Mail 7.1 \(1827\))
X-MIME-Autoconverted: from quoted-printable to 8bit by delorie.com id s0DLaAMS005491

I am running Cygwin 1.7.27 (0.271/5/3) and g++ 4.8.2. 

I am testing attempts to make temporary files in a POSIX-compliant way, using mkstemp().

I get the following error when I compile code that calls mkstemp():

-----------------------------------------
$ g++ -Wall -ansi -pedantic foo.cpp
foo.cpp: In function ‘int main()’:
foo.cpp:44:21: error: ‘mkstemp’ was not declared in this scope
-----------------------------------------

Here is my code:

-----------------------------------------
#
# foo.cpp
#

#include <stdio.h>
#include <cstdlib>
#include <unistd.h>
#include <sys/stat.h>
#include <cstring>

#ifndef P_tmpdir
#ifdef _P_tmpdir
#define P_tmpdir _P_tmpdir  /* MingW */
#else
#define P_tmpdir "/tmp"
#endif
#endif

int main ()
{
 char const* p = getenv("TMPDIR");
 if ( p == NULL )
   p = P_tmpdir;
 printf("%s\n", p);

 int fd;
 char* tmpl = (char*)malloc(1 + strlen(p) + L_tmpnam);
 printf("%d\n", L_tmpnam);
 printf("%ld\n", strlen(p) + L_tmpnam);
 strcpy(tmpl, p);
 strcpy(tmpl+strlen(p), "/sb.XXXXXX");
 printf("%s\n", tmpl);

 mkdir(p, 0700); // ignoring return val... mkstemp will fail if directory isn't writable
 if ( (fd = mkstemp(tmpl)) == -1 ) {
   fprintf(stderr, "unable to create temp file!\n");
   return EXIT_FAILURE;
 }
 printf("%s\n", tmpl);

 printf("%d\n", remove(tmpl));
 printf("%d\n", remove("this-aint-no-file"));

 free(tmpl);

 return EXIT_SUCCESS;
}
-----------------------------------------

Is mkstemp() part of Cygwin? If not, what options would I have to replace this code with equivalent functionality?

Thanks,
Alex
--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019