I want to create MySQL connection in one function (file) in a C project and then use that connection globally (access it in every function or file in the project). Is that possible and what is the logic (pattern) I should follow?
Thanks!
I'm not experienced in MySQL but presumably the connection is stored in a variable after you make it, perhaps a MYSQL*. Therefore, you can just use the standard way to share global variables across files in C. See: How do I share variables between different .c files? , How do I use extern to share variables between source files?
Related
Using Linux, I want to redirect access to files according to the app accessing them. For example:
App1: when trying to access "/foo/bar", access /foo1/bar1
App2: when trying to access "/foo/bar", access /foo2/bar2
The way I tough into doing this is by overwriting fopen and related functions using LD_PRELOAD.
My two questions:
Would be this strategy language independent?
Edit: by language independent I mean it will not be affected by what language app1 and app2 are built.
There are better approaches, or maybe something already existing to achieve my goal?
Thanks
Edit: to simplify the question, think of /foo as symbolic link which resolves differently according to the app trying to access it.
For my particular case, the best option is to use LD_PRELOAD to overwrite open, open64, etc.
If you are facing a similar problem, check also chroot, jail root and docker container.
I'm changing a program written in C.
For these changes I need a counter (variable int). When the run stops, I need the value of this counter in the following run of the program. (even if the pc is restarted in between).
What is the best way to store this value? I was thinking about the following : storing it as a registry-value, writing it to a file (not preferred, somebody might delete this file), using persistent variables (but I can't find many information on these).
Or, are there other ways to keep this variable?
The program has to run in a Windows environment and in a Linux environment (as it does now).
Store it in a file. If you want to protect the file from accidental deletion, have its name start with a period on Linux (.myfile) or mark it as "hidden" on Windows. If you want to protect it against more than just accidental deletion, the registry is no better than a file.
The best solution I think would be to store it in a database. Have you got any database experience? Could you store it in MySQL or SQL Server?
C doesn't have a concept of "persistent variables"; no actual programming language that I know of has that.
A file would be the best choice; detecting its absense and protesting/failing will be trivial.
I'm trying to control mutliple Eclipse configurations through SVN. For that purpose I need to know in which files does Eclipse store his configurations. What I could not find, is where are the driver definitions stored (I mean the stuff which is set up at Preferences->Data Management->Connectivity->Driver Definitions). Does anybody know that?
Those are stored at <Workspace>\.metadata\.plugins\org.eclipse.datatools.connectivity.
I am working with a MATLAB project, and would like to be able to configure variables and paths without re-creating the executable (currently done by using MATLAB's built-in deploytool). I realize I can create a simple text file, listing key=value pairs, and read that in during run-time. There doesn't seem to be any built-in support in MATLAB for creating configuration files that follow a standard format.
Are there any standard existing ways to use configuration files for MATLAB-generated executables?
1) Add your resource to the package in DeployTool in the shared resources part
2) Read by using:
fullfile(ctfroot(),'config.txt');
Edit : That is suitable if your configuration is "private", that is the user should not edit it. In this case it is deployed together with your program as a resource. If you want a "public" config for the users, I know of no better way than to do what you offered.
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.