Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I am trying to check if file that i want to create is executable.
The check will be by given file path, for example:
c:\good.txt
I want to check if file is executable before I will create it.
I think to use this function:
with the SHGFI_USEFILEATTRIBUTES flag, but I can't use this flag with the SHGFI_EXETYPE flag.
It means that I can't use the SHGFI_EXETYPE flag on a non exiting file.
Is there any another way to check if file is executable before I create the file?
A file that does not exist cannot be ether executable or non-executable. The executability of a file (or otherwise) is stored within its metadata, be that a filename, permission bits, attributes or whatever. A file that does not exist has none of those, and hence you cannot check for its executability.
You'll notice that the SHGetFileInfo function to which you refer is document thus:
Retrieves information about an object in the file system, such as a file, folder, directory, or drive root.
Note the bit about it retrieving information about an object in the file system (not 'an object not in the file system).
A file which doesn't exist is not executable. You're asking a question which doesn't make sense. 'How hot is the water in this empty glass?' - how can something which doesn't exist have a property?
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I'm trying to build a big project step by step. I'm working on Linux and using qt-creator and gcc compiler. I include a set of related files in the .pri file and then build, test functionality and then add a new set of existing files and so on.
The project compiled successfully then I included a folder containing some header files then when compiled I got many errors in libc-header-start.h, string.h, cpu-set.h, time.h and many other stdlib and system files. Errors like missing binary operator before token (, unknown type name __cpu_mask, expected ';', ',' or ')' before '*' token.
I think these are likely to be preprocessor errors that are caused, for example, if I forget a semicolumn or so, right?
My question is, how can I locate the exact location in the header/source files where all these errors started, for example, the line of code where the semicolumn is missing.
This answer is just collecting the comments on my question.
Here is what can help locating what is the root cause of preprocessor errors:
Make sure that the names of your header files don't conflict with standard header files.
Check the first file in the errors list. Check where this file is included. If this file is included by another standard header file, check where the parent header file is included in your code. The root cause of the errors may be in the lines before that #include statement in your code. For example, you may have forgetten a semi-column before this #include.
Use gcc -H file.c to check all the header files included with file.c.
Use gcc -E file.c to generate a preprocessed version of file.c, then you will have the full end picture of your file which you can then investigate.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I'm creating a project and I need to call my executable file name "cluster".
I created a makefile and as long as I call my executable file name by any name other then "cluster" and runs it, it works fine.
However, when I'm calling the file name "cluster" -> make all -> executing (with the name "cluster") I receive the following error:
The error message
What could be the cause of this error? I must be able to call the executable file name that specific name.
If you are on linux, type
which cluster
You will probably find a program called cluster on your path. To execute the one you have made, either change the name to something like Cluster or
./cluster testGraph8 outputfile
The ./ uses the one in the current directory.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
Picture of code
I have a problem with clang 7 error, I don't know what the issue is? Why is clang -o hello hello.c not working? I have already tried twice and the error repeated itself so I am unsure why the clang -o hello hello.c is not working.
Read the messages. The clang command told you:
/usr/bin/ld: cannot open output file hello: Is a directory
The “/usr/bin/ld:” part says the specific program “/usr/bin/ld” (which is the linker; it links object files into an executable file) is giving you this message.
The “cannot open output file hello” part says it cannot output the file named “hello”.
The “Is a directory” part says why there is a problem: “hello” is a directory, meaning it exists and is a directory, not a regular file, so it cannot be opened like a regular file. The linker wants to open it as a regular file so that it can write to it.
To fix this, either remove or rename the directory named “hello” (check what is in it first, to see if you want it) or use a different output file name in the clang command.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 3 years ago.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Improve this question
I have a program written in C that creates and reads a config file. It assumes that the config file is in the same directory as it is.
The program is run by fcron as root. If root runs this program, then the config file is created in root's home directory. It needs to be created in the user's directory where the program is.
I don't know enough about user management in linux to solve this, so the only way I can think to solve this is to get the executable's path by modifying argv[0].
Is there a better way?
Does the program have to run as root? Using the crontab for the user would ensure the right home directory, file permissions, etc. as well as security advantages.
You could modify the job to run in a desired working directory. I believe the syntax would be something like:
15 7 * * * cd /home/myuser/ && /usr/bin/myprogram
Or pass it as an argument, (see various programs for examples of things like --config-path=~/mycustomconfig). These have more flexibility, say if the program is installed once for multiple users.
Alternatively, to get the main executable path in the process, you can read /proc/self/exe, you might then use dirname to get the directory from the full path. e.g.
char path[MAX_PATH];
ssize_t len = readlink("/proc/self/exe", path, MAX_PATH);
if (len > 0 && len < MAX_PATH) {
path[len] = '\0';
char *directory = dirname(path);
}
In either case, the regular file I/O functions will create a file owned and writable by root, if this is not desired, chown(path, owner, group) might be used. stat(path, buf) on the home directory could be a way to get the ID for chown but not something I ever considered and there may be cases the directory is owned by the "wrong" user.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have seen C programs split into .h files with its respective .c files.
I know that header files are for macros/declarations/function prototypes and .c files for function definition.
But how are those .c got used ? passed by compiler's command line?
The C files are not combined by the compiler, but by the linker. Depending on how you compile your code this may be hidden from you.
The compiler will compile each of the C files into an object file for each C file. Then the linker will take these object files and combine them into an executable file or a library file.
2 options:
Pass the .c files to the compiler's command line, all together, for a "compile and link all in one" command. You usually only do that for toy and very small projects
compile each .c file individually (giving it as a separate compile command line), generating .o files. Then passing all these .o files together to the linker (normally it's the same command as the compiler...) to create your executable. This way if you change a .c file you only have to compile that file (to create its .o file again) and link, saving a lot of time.