Solved

C function: mktemp() is not working under linux

Posted on 2014-04-17
7
370 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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Help needed with BIND9 DNS on Ubuntu. 22 68
unix in java example 9 43
Linux operating system 12 66
Edit linux file using python 4 21
If you have a server on collocation with the super-fast CPU, that doesn't mean that you get it running at full power. Here is a preamble. When doing inventory of Linux servers, that I'm administering, I've found that some of them are running on l…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
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.

762 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

24 Experts available now in Live!

Get 1:1 Help Now