Solved

C function: mktemp() is not working under linux

Posted on 2014-04-17
7
376 Views
Last Modified: 2014-04-17
I have a c program that used the mktmp function.  It is no longer working since we shifted from HPUX to a Linux environment. I googled and found out that I shouldn't be using mktmp() anymore:
http://man7.org/linux/man-pages/man3/mktemp.3.html

Here is the code, written a long time ago by someone else and my C programming is not sharp (small pun intended):

/* try to create temporary file to hold per-dept recap lines */

    strcpy(recapfilename, "/tmp/tstaff-recap-XXXXXX");
    mktemp(recapfilename);
#ifdef JCCDEBUG
    fprintf(stderr, "%%recap file name is '%s'\n", recapfilename);
#endif /* JCCDEBUG */
    recapfp = fopen(recapfilename, "w+");
    if (recapfp == NULL)
    {
        fprintf(stderr, "%%unable to open recap file '%s'\n", recapfilename);
    }
#ifdef JCCDEBUG
    else
    {
        fprintf(stderr, "%%recap file '%s' opened OK\n", recapfilename);
    }
#endif /* JCCDEBUG */

Can someone give me the new function to use?  When I run the program I get the 'unable to open recap file. So I am sure that is where it is failing when trying to use the mktmp() function.

Thanks in advance!
0
Comment
Question by:dcrowley_01
  • 3
  • 3
7 Comments
 
LVL 5

Assisted Solution

by:Pasha Kravtsov
Pasha Kravtsov earned 250 total points
ID: 40007392
0
 

Author Comment

by:dcrowley_01
ID: 40007406
I changed it to mkstemp() and I get the same error:

unable to open recap file

So it appears the code is ok, but their must be some difference between the environments.
Has anyone ever run into this before?

Can I re-write it so that it doesn't need to write the temp information out to a file and instead holds it in memory or something?
0
 
LVL 5

Expert Comment

by:Pasha Kravtsov
ID: 40007416
Can you copy and paste the error? And mktemp() according to the man pages is a security risk.
0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 

Author Comment

by:dcrowley_01
ID: 40007456
The error is: %unable to open recap file ''
0
 
LVL 5

Expert Comment

by:Pasha Kravtsov
ID: 40007465
see if mkstemp() is returning NULL
0
 
LVL 86

Accepted Solution

by:
jkr earned 250 total points
ID: 40007511
Do you (i.e. your account) have permissions to access the directory that holds the temporary files?
0
 

Author Comment

by:dcrowley_01
ID: 40008001
This is not a code problem. Something else is going on with the OS. Going to close the question and split the points.
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Setting up two Raspberry Pi gateways/routers 3 60
Penetration Testing home based work 3 73
installing docker on ubuntu 6 28
windows 7 starter missing password 21 74
The purpose of this article is to demonstrate how we can use conditional statements using Python.
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

816 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now