header file for the function poll - c

I am trying to create a chat application with a non-blocking socket. for this I am supposed to use the poll() function. I understand that I've to include the "poll.h" header file but my compiler says "No such file or directory found",On the other hand If I don't include this file my code accepts the structure pollfd,it compiles fine but at run time gives me the error that the variable "P is used without being initialised"(I defined "P" to be a pollfd variable)
could some one tell me what should I do in this situation...
Is it possible to download header files?
I am working on visual studio 2008.

According to this forum post, you can try using select() instead of poll(), which Windows does not support. You could try to download the libraries and header files that you need, but those may in turn rely on platform-dependent libraries, bringing you back to square one.
You'll want to use the Windows implementation of select(), of course. Here's the link. The header is file is Winsock2.h.

Related

Change which file vscode opens when using "go to definition"

I'm using Visual Studio Code to manage a C project that contains a number of libraries and fully-linked executables. When the executables need to depend on headers from a library, rather that point at the library's source files directly, they point at a build directory containing the headers. That is, for a source layout like:
project/lib/src/lib.h
project/exe/src/exe.c
Rather than the build for project/exe including -I project/lib/src, it does -I project/lib/build, which will have a copy of lib.h in it from the last time the library was built. This is done for miscellaneous reasons that don't matter here, and mostly works fine, except when I use vscode's "Go to Definition" feature (F12, Ctrl+Click, etc.).
Because vscode is using the compiler's include path to know where to find headers, if I go to the definition of anything in lib.h, vscode will open project/lib/build/lib.h instead of project/lib/src/lib.h. Is there a way, either built-in or via a plugin, to hook vscode's belief that it should open project/lib/build/lib.h and change it to project/lib/src/lib.h? I'm even willing to write a plugin, but I couldn't find a way to either modify the language server's result to change the path, or intercept vscode attempting to open a particular path and change it on-demand.

Forcing eclipse indexer to always use specific header file when opening declaration

I've got a very huge C project that is meant to be built on Solaris. I use a Windows PC for most of my work, ssh'ing into a solaris box when I need to make edits and build the code.
I've recently imported the project into Eclipse (Luna) on my Windows machine from GitHub for ease of traversing the code. One problem I'm having is that the indexer cannot seem to determine which header file a particular declaration is coming from... I mean it's not able to tell that an enum in alarm.c can be found in alarm.h (as alarm.h is included in alarm.c), because that same enum (ERROR, for example) can be found in a couple other header files in another part of the project. See the image for what happens when I press F3 on one of the enums with multiple declarations in the project:
Is there a way to force the indexer to always use alarm.h when it has anything to do with alarm.c source code? Can I have it ignore the rest of the project? It would really aide in getting rid of the thousands of "errors" in the project which are specifically related to "multiple declarations found" by the indexer.

Is it possible to open an anonymous file in windows?

I would like to open an anonymous file that is what would be the result under linux of opening a file an unlink it or using memfd_create, but none of these seem to be available under windows (you could make delete a file work, but it's name doesn't seem to be removed until the file is closed). Getting a file descriptor that isn't backed with something visible in the file system.
Is there a way to achieve this under windows? Preferably I'd like it to never appear in the file system.
The reason why I want this is because I need a FILE* to be sent as an argument to a function that expects that (and I don't want it to clobber the file system). Changing the libraries does not look like a feasible option (besides the libraries has to work on other OSes as well - so they can't rely on windows specific abstractions anyway).
The most reasonably close to memfd_create you have in Windows are Memory-Mapped files. MSDN article about it here: http://go.microsoft.com/fwlink/?linkid=180801
But basically, the CreateFileMapping/OpenFileMapping API calls.
This does not use the physical disk (unless it needs the memory paged on disk) for it, but as far as I know, neither does memfd_create
No, there is no such thing as an anonymous file in Windows.
(Of course, that does not necessarily mean that you cannot have a FILE * that does what you need; for example, I like Ross's suggestion of using a named pipe.)

Can we lock file or folder in ubuntu by using open CV and C

I want to create a project to lock file and folders in ubuntu by face detection through opencv using C language. Can you please let me know it is possible and how can i do it.
Can't help you with the opencv part, but "lock file and folders" could mean a few things:
You want to change permissions of files so that a given user/group can/cannot
access them. If this is the case, you want the chmod function.
See man 2 chmod. Seems like this is probably what you're after?
Usually, "file locking" on Linux refers to a means to prevent other processes from accessing a file without changing permissions via either:
Mandatory file locking via lockf (or fcntl).
Advisory file locking via flock.
If file locking is what you're after, here are the "see also" documents referred to by the man pages on lockf and/or flock:
https://www.kernel.org/doc/Documentation/filesystems/mandatory-locking.txt
https://www.kernel.org/doc/Documentation/filesystems/locks.txt
Note: Others have indicated you might want to use the C++ API for opencv. All of these functions should work just fine from C++ too.

How to create a header file for my existing C program in linux to connect with MySql?

it's my first time I use Linux and C programming. I've wrote a file in C language to connect with MySQL and it's working fine now. Now I've to integrate this file into my company web-based system which is written with CGI ( C ). So I guess I should make my file as a header file and call this file from the CGI. How should I create a header file ? Or is there any better way ? I google on the net but not so lucky with CGI. Can anybody help me?
I don't think that putting everything in a header file is the best solution.
Create a header file and put the
function prototypes and structure
declarations in it
Create a C file and put function definitions in it
Then you can either link with the object file obtained or you can create a dynamic library.

Resources