POSIX/MinGW compatibility: mkdir('/tmp/randompath') fails - c++

I need to create temporary folder in C/C++ library, and make it compatible with Windows/MinGW.
While mkdir("/tmp/something") works well (with permissions parameter of course) under Linux/macOS/whatever else, it fails under MinGW with ENOENT error.
Do I correctly understand that since _mkdir() is Windows API call then it should contain Windows path (i.e. will not be translated from /tmp/...) ?
And, then, what will be correct solution to access temporary folder? Use $TEMP environment variable? Any other ways via some WinAPI calls?
Thanks.

Related

How to use the UNC format to specify a full root-name in Windows

I am trying to work with UNC to access files on Windows on a partition that does not have a drive letter. The UNC I am trying to use (as returned by mountvol) is
\\?\Volume{6ed63a9f-b672-4f57-8c22-8dd824dd793e}\
Using powershell Get-ChildItem -Literalpath or even dir -l (with the UNC above) works perfectly well.
But using std::filesystem I get an exception that says Invalid Argument.
I try
\\?\Volume{6ed63a9f-b672-4f57-8c22-8dd824dd793e}\data\somefilename
and
\\?\Volume{6ed63a9f-b672-4f57-8c22-8dd824dd793e}\\data\somefilename
without success. What is the correct format?
EDIT
Well, using the fileapi from Windows (CreateFile and ReadFile) works as expected. So my string that identifies the file is perfect.
The only issue is that I would really have preferred to use std::filesystem, since this is what I use in my file access wrapper.
Is this a bug in mingw-w64? I am using
x86_64-w64-mingw32-g++ (GCC) 10-posix 20220113
on Ubuntu 22-04

C++ : How to get actual folder path when the path has special folder names

I am trying to find a way to convert a path like this: "%APPDATA%\xyz\Logs\Archive" to this: "C:\Users\abcUser\AppData\Roaming\xyz\Logs\Archive".
I am on Windows platform. I use Unicode character set. I can use C++17 if required. I can use boost libraries if required.
In my search so far, I came across the SHGetKnownFolderPath() function. And there are StackOverflow references that explain how to resolve %APPDATA% to its actual path:
How do I get the application data path in Windows using C++?
C++ CreateDirectory() not working with APPDATA
The Win32 API that expands environment variable references of the form %variable% in strings is ExpandEnvironnmentStrings.

Use autotools installation prefix

I am writing a C++ program using gtkmm as the window library and autotools as my build system. In my Makefile.am, I install the icon as follows:
icondir = $(datadir)/icons/hicolor/scalable/apps
icon_DATA = $(top_srcdir)/appname.svg
EDIT: changed from prefix to datadir
This results in appname.svg being copied to $(datadir)/icons/hicolor/scalable/apps when the program is installed. In my C++ code, I would like to access the icon at runtime for a window decoration:
string iconPath = DATADIR + "/icons/hicolor/scalable/apps/appname.svg";
// do stuff with the icon
I am unsure how to go about obtaining DATADIR for this purpose. I could use relative paths, but then moving the binary would break the icon, which seems evident of hackery. I figure that there should be a special way to handle icons separate from general data, since people can install 3rd party icon packs. So, I have two questions:
What is the standard way of installing and using icons with autotools/C++/gtkmm?
Edit: gtkmm has an IconTheme class that is the standard way to use icons in gtkmm. It appears that I add_resource_path() (for which I still need the installation prefix), and then I can use the library to obtain the icon by name.
What is the general method with autotools/C++ to access the autotools installation prefix?
To convey data determined by configure to your source files, the primary methods available are to write them in a header that your sources #include or to define them as macros on the compiler command line. These are handled most conveniently via the AC_DEFINE Autoconf macro. Under some circumstances, you might also consider converting source files to templates for configure to process, but except inasmuch as Autoconf itself uses an internal version of that technique to build config.h (when that is requested), I wouldn't normally recommend it.
HOWEVER, the installation prefix and other installation directories are special cases. They are not finally set until you actually run make. Even if you set them via the configure's command-line options, you can still override that by specifying different values on the make command line. Thus, it is not safe to rely on AC_DEFINE for this particular purpose, and in fact, doing so may not work at all (will not work for prefix itself).
Instead, you should specify the appropriate macro definition in a command-line option that is evaluated at make time. You can do this for all targets being built by setting the AM_CPPFLAGS variable in your Makefile.am files, as demonstrated in another answer. That particular example sets the specified symbol to be a macro that expands to a C string literal containing the prefix. Alternatively, you could consider defining the whole icon directory as a symbol. If you need it only for one target out of several then you might prefer setting the appropriate onetarget_CPPFLAGS variable.
As an aside, do note that $(prefix)/icons/hicolor/scalable/apps is a nonstandard choice for the installation directory for your icon. That will typically resolve to something like /usr/local/icons/hicolor/scalable/apps. The conventional choice would be $(datadir)/icons/hicolor/scalable/apps, which will resolve to something like /usr/local/share/icons/hicolor/scalable/apps.
In your Makefile.am, use the following
AM_CPPFLAGS = -DPREFIX='"$(prefix)"'
See Defining Directories in autoconf's manual.

wxFileName:;Mkdir(Filepath,0777,wxPATH_MKDIR_FULL) is not working in LINUX

I'm Trying to make a directory with path(eg:/user01/newpath) by using wxFileName::Mkdir with permission 0777. But the code is not working in some linux systems which has same specifications as like my system. the problem is after creating 'User01' folder it is not creating 'newpath' folder and I observed like "User01" folder has a Lock symbol.
syntax which I used is: wxFileName:;Mkdir(Filepath,0777,wxPATH_MKDIR_FULL) ;
Please, tell is there any function which will work other than mkdir, wxMKDir, wxMKdir(these also have same problem)??
thanks,

vs10 C++ $(MyLibrary) vs %(MyLibrary)

We are using an environment variable to specify a path to a library we use. Most of the time it points to the released version but sometimes to a development version.
Anyway, it works ok when I use $(MyLib)/path;%(AdditionalIncludeDirectories) for building the C++ application but I can not open the project resources. However, when I use %(MyLib)/path;%(AdditionalIncludeDirectories) it works.
Now, what is the difference?
I thought the correct way is to use $(EnvVar) but for the resource editor it doesn't seems to work. And if $(EnvVar) is the correct way then why does Visual Studio use %(AdditionalIncludeDirectories) and not $(AdditionalIncludeDirectories)
The error I get is: fatal error RC1015: cannot open include file 'afxres.h'.
You use %(item) to refer to an MSBuild metadata item. Using $(AdditionalIncludeDirectories) would not work well if you also had an environment variable by that name. So %(MyLib)/path ought to resolve to just /path.
You can put echo %(MyLib)/path in a prebuild event to verify this.
Which is probably enough to stop confusing rc.exe, the resource compiler. Which is a stone-cold-old SDK utility, going back all the way to Windows version 1.0. It is pretty temperamental, very picky about command line options and .rc script file text encoding. Do keep in mind that it dates from an era long before Windows started to support a forward slash as a path separator, everybody had to use a backslash back in 1986.
So use "$(MyLib)\path" instead, including the double quotes so you don't confuzzle it when MyLib contains embedded spaces. And do favor using a project property sheet instead so there are some odds that somebody can still figure out how to get the project built correctly 2+ years from now.