Results 1 to 10 of 10
Hi all!
I use ubuntu 9.04;
I have a function called "isLogEnabled" in my project on windows, I wanna port it to linux.
I know that I should have a ...
- 06-23-2010 #1Just Joined!
- Join Date
- Sep 2009
- Posts
- 27
Problem in "porting" a function on windows to linux?
Hi all!
I use ubuntu 9.04;
I have a function called "isLogEnabled" in my project on windows, I wanna port it to linux.
I know that I should have a "config.h" file in linux to get log from a specific Shared object and ..., but because I'm new to linux,
I don't know how this should be done, this is my function:
Since I think we don't have registry concept in linux and this function uses registry APIs, I'm confused to change it to be compatibleCode://This function return True if log policy is set in registry and False otherwise int isLogEnabled() { HKEY hKey; LONG lRes; DWORD dwType, dwSize = 0; int retVal = 0; if((RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\MyCorp", 0, KEY_ALL_ACCESS, &hKey)) == ERROR_SUCCESS) { lRes = RegQueryValueEx(hKey, "SpecialMode", 0, &dwType, NULL, &dwSize ); if(lRes == ERROR_SUCCESS) retVal = 1; RegCloseKey(hKey); } return retVal; }
with linux;
Could you help me with this please?!
TIA.
- 06-23-2010 #2
if this is some kind of configuration value, usually config files are stored in /etc for applications on linux, then you should store the config values in a file there and look into the file for specific values
- 06-23-2010 #3Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,974
Your code is very specific to Windows functionality and Visual-C programming. You need to determine what you want to do, and figure out how to do that in standard C or C++ without dependencies on Windows code and characteristics. This may be simple, or not, depending upon the complexity of the problem.
So, what do you MEAN by the function name 'isLogEnabled'?Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!
- 06-30-2010 #4Just Joined!
- Join Date
- Sep 2009
- Posts
- 27
Hi and thanks for your help!
My config file would only contain "retVal = 1", because this is the return value of "isLogEnabled" function and in my main function it's checked as below:
if(isLogEnabled())
initLogger(LOG_FILE);
If I don't use the libconfig functions and just want to load the config file content(retval), what should I do?
I mean:
I should open a gedit text and only write "retval=1" in it, I name it "Mainconf" but I don't know what would I define it's extension(.cfg or .config or ...)?
I should save it in /etc directory, now how can I load it to my program to check it and what would be the alternative for the part:
if(isLogEnabled())
initLogger(LOG_FILE);
in linux?
I'm new to software developing in linux, Please guide me!!
THX again.
- 06-30-2010 #5
you could use syslog - <syslog.h>
i'm not a c/c++ guy, so this was just a 5 second google thing
- 06-30-2010 #6Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,974
Well, your code:
is perfectly resonable syntax for any C or C++ application. I am still unclear on what your problem is. Linux doesn't use a registry, but it often uses configuration files in /etc such as /etc/samba/smb.conf as an example, which will contain this sort of information. When the associated program starts, it reads this configuration file and sets its internal variables accordingly.Code:if(isLogEnabled()) { initLogger(LOG_FILE); }Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!
- 06-30-2010 #7Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,974
Note that a lot of a program's configuration information may also be found in /opt/program-name or /usr/share/program-name instead of /etc. /etc is usually reserved for more system-level servers and such. So for example, the configuration information for OpenOffice can usually be found in /opt/openoffice.org/share/config or /opt/openoffice.org/share/registry. Where precisely these configuration files are found, what format they are in, and what data they contain, is entirely up to the application in question.
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!
- 06-30-2010 #8Just Joined!
- Join Date
- Sep 2009
- Posts
- 27
I exactly want this!
when my program .exe is run, how does it read the config file and check the "retval" value in the program to see if it is "1" to run the next line!
Should I use an API to open this config file in the "main" function and an API to read and check "retval" instead of the code:
or not?Code:if(isLogEnabled()) { initLogger(LOG_FILE); }
I don't know the process of this operation:
And could you guide me what the apprpriate APIs are to open a file, read it's content, etc... for my purpose please?!When the associated program starts, it reads this configuration file and sets its internal variables accordingly
And also what's the answer of this question:
I'll highly appreciate if you reply completely again.what would I define it's extension(.cfg or .config or ...)?
THX so much.
- 06-30-2010 #9
extension doesn't matter, you can do whatever you want
- 06-30-2010 #10Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,974
Opening/reading files are standard Unix/Linux operations. You need to review the standard C API functions for file handling - basic Computer Science 101 stuff. You can find most of that in Kernighan and Ritchie.
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!


Reply With Quote
