Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 409
  • Last Modified:

C function: mktemp() is not working under linux

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
dcrowley_01
Asked:
dcrowley_01
  • 3
  • 3
2 Solutions
 
Pasha KravtsovSupport EngineerCommented:
0
 
dcrowley_01Author Commented:
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
 
Pasha KravtsovSupport EngineerCommented:
Can you copy and paste the error? And mktemp() according to the man pages is a security risk.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
dcrowley_01Author Commented:
The error is: %unable to open recap file ''
0
 
Pasha KravtsovSupport EngineerCommented:
see if mkstemp() is returning NULL
0
 
jkrCommented:
Do you (i.e. your account) have permissions to access the directory that holds the temporary files?
0
 
dcrowley_01Author Commented:
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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now