?
Solved

C function: mktemp() is not working under linux

Posted on 2014-04-17
7
Medium Priority
?
397 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 5

Assisted Solution

by:Pasha Kravtsov
Pasha Kravtsov earned 1000 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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 1000 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

Get proactive database performance tuning online

At Percona’s web store you can order full Percona Database Performance Audit in minutes. Find out the health of your database, and how to improve it. Pay online with a credit card. Improve your database performance now!

Question has a verified solution.

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

Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
Suggested Courses
Course of the Month9 days, 3 hours left to enroll

764 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