Re: Secure C library - fopentmp_s (a usable secure create and open named temporary file)



Jonathan Leffler wrote:
I was faintly hoping to avoid having to do that. I fully accept that as proposed, fopentmp_s() does not permit you to specify:
* Created file access permissions.
* A template (that is, directory location) for the created file.
* The file mode (I mentioned "wb+" because the tmpfile_s() does).
I would like to be able to specify all three.

errno_t fopentmp_s(FILE **stream, const char *mode, char *fname, rsize_t fname_size);

[...]
fname shall contain the (possibly empty) initial portion of the filename to be generated. The filename is then generated by filling the remaining {bytes/characters?} of fname[].
[...]



Although this specification would allow many different implementations, the drawback is that it assumes that the initial portion of a filename has some useful interpretation, like directory names in POSIX and Windows. An implementation where the order of directories were reversed, like "file|dir|drive", would not benefit from this specification.


Portable applications should then always leave the fname empty to allow the implementation to choose freely from the set of available filenames.

FILE *f;
char fname[80];

fname[0] = '\0';   /* allow arbitrary file names */

if (fopentmp_s(&f, "a+", fname, sizeof(fname)) == 0) {
    ...
}

Another possibility would be to add a template parameter which specifies (in an implementation-defined manner) how the filename is to be constructed. This could be the initial portion of the filename on POSIX and Windows, and maybe the final portion on my imagined implementation with the reversed pathnames.

Roland
.



Relevant Pages

  • Specify directory to save to
    ... I have a template which automatically generates the dates for the ... It also sets the filename to be those dates. ... to save it in some odd temporary folder. ... How can i specify what ...
    (microsoft.public.word.vba.general)
  • Re: Reporting Services and Excel
    ... Once again Keith, your advised has helped me tremendously, Thanks!!..In terms ... of the name of the file, I noticed that you can specify a filename if you are ... saving the report to a fileshare directory but you cannot specify a filename ...
    (microsoft.public.sqlserver.server)
  • RE: Excel Macro
    ... *I could get the date from a cell in the spreadshee and format dd.mm.yy ... And is that mm.dd.yy or dd.mm.yy for part of the filename? ... Dim theMonth As String ... 'before the date portion of the filename ...
    (microsoft.public.excel.misc)
  • Re: Filename Problem
    ... specified which is then opened and loaded into the matlab workspace. ... [filename, pathname] ... The easiest thing is to specify an output argument for load: ...
    (comp.soft-sys.matlab)
  • File Upload - ValidationExpression (ASP.NET). Please help!!!
    ... "You must specify the file location and the filename must follow this ... Do I need to put it in ValidationExpression? ...
    (microsoft.public.dotnet.framework.aspnet)