Is there a C library function to get the extension of file? I know that I can design a function on my own to get extension after '.' but not all files are stored with their extensions when we read them.
So you'd like to get the type of a file? Maybe the command 'file' in Linux is what you want. You can check its source code.
The file command in Linux uses a library called libmagic (don't confuse with libmagick) to check the 'magic' bytes in the file itself to determine the likely content type.
The library is fairly cross platform, it's well documented, for example here:
http://linux.die.net/man/3/libmagic
Related
Due to my job, I have to develop software with only C but not C++.
It will be good that when I write class A {}; Vscode will display an error or a warning.
Now I use clangd, it will be great if some settings can satisfy.
Clangd will correctly issue diagnostics for C++-only constructs, if it's parsing your file in C mode.
So it's a matter of making sure clangd is parsing your files in the correct language mode.
If your file's extension is unambiguously a C-language extension (for example, .c), then clang should parse the file in C mode automatically.
If the extension is ambiguous, like .h, then clangd attempts to choose the language heuristically, which can sometimes give a wrong answer. In this case, you can specify the language explicitly in the file's compile command, for example by adding -x c-header to specify "parse as a C header".
One way to do this is using CompileFlags: Add: in the clangd config file. For example, to specify that all .h files in the project are C headers, you might add the following to the project .clangd file:
If:
PathMatch: .*\.h
CompileFlags:
Add: [-xc-header]
I want to localize my application using the catopen()/catgets() family of functions.
As far as I understand, in the absence of NLSPATH variable, message catalogs will be looked up under /usr/share/locale/xx_YY/LC_MESSAGES.
What is the "traditional" file extension for message catalog files? I see some code examples using *.cat while others don't use any extension at all. Is it dependent on a particular UNIX flavour?
On my Linux boxes I see plenty of *.mo files, but those are GNU gettext archives. It seems catgets() can rarely be seen "in the wild" nowadays.
I meant this to be a comment, but it's a bit too long :P
Looking at the doc you've linked to, it seems probably that the code isn't opinionated as to file extension. Since you're not using MIME or anything to automatically find a handler for this file, the only requirement is likely to be that the name is correct. In UNIX, especially in the shell, file extensions often mean nothing to the system - fo example, any file extension can be used on an executable script as long as the executable bit is set and the shebang line at the top of the file specifies an appropriate interpreter.
It's possible the user community, if one still exists for this crufty sounding library, has a standard naming convention that the docs don't describe - but I wouldn't sweat it too much. It's trival to change file names, even if it means a recompile ( command line variables would make the program agnostic as to file name and extension )
I just realized I don't know how file is called in file.ext.
The whole file.ext is called a file or filename, ext is called extension but how do you call the file part itself of file.ext?
For example happy-dog.png. All the file/filename is happy-dog.png, extension is png but how do you call happy-dog?
It's not basename. Is it like titlename? Or filepart? Any ideas?
I believe there is no short name for this thing. Some libraries just refer to it with names like "filename-without-extension" or "filename-without-path-or-extension".
You could use the term "basename", because that is the program or function often used to generate this thing. It is not quite accurate because basename may or may not strip the extension depending on what arguments you pass it, but I think programmers would understand you.
FileBaseName[] in Mathematica.
I wants to get the names of execute files in some directory in Linux.
How can I do it?
I tried to use opendir like this:
dir = opendir(directoryName);
I need to get only the names of the execute files.
I programming in C.
thanks :)
You should define what you mean by executable files.
That could be any file with its execute bit (it is the owner, group, or other) set. Then test with access(2) & X_OK and/or use stat(2).
That could also be only ELF executables. See elf(5); then the issue might be to check that a file could indeed be executed, which might be difficult (what about missing library dependencies? or ill-formed ELF files?). Maybe use libelf (and/or libmagic to do the equivalent of file(1) command).
To scan recursively a file tree, use nftw(3); to scan just a directory use opendir(3) & readdir(3) (don't forget the closedir!), then you'll probably need to build the complete file path from each directory entry (perhaps using snprintf(3) or asprintf(3))
See also Advanced Linux Programming
I was looking at getting HTML-XML-Utils working on my computer and I noticed the .e filetype in the source tree. Running:
% file types.e
types.e: ASCII c program text
reveals some clues about it and its use in C files seems to be that of a header file.
Can anyone reveal some more information or history about this filetype? I've tried my best Google-foo but I cannot find anything.
I never heard of that file type in connection with C before, but after checking the files and the Makefile it seems to be variables and functions that are exported, therefore the .e extension.
They seem to be created by a special program (which comes with the package) called cexport whose manual page states:
cexport - create header file with exported declarations from a C file