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
Solved

C function: mktemp() is not working under linux

Posted on 2014-04-17
7
378 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

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…
Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

860 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