I am currently trying to build a new version of a piece of software I developed. The software takes a simple command line argument and appends the argument to the end of a file. My problem is that I want to alter the program so:
Someone can set up a standard location to save the file to.
The program will remember that location.
It will still work for anyone installing the C program on mac, linux or windows.
So basically I am trying to figure out how to create a C executable that comes with persistent memory that it can read and modify. Alternatively I would take any way to create an installer to make this easy for anyone who wants to use my program.
If this were a java program I would just add it to the jar file but I have never seen this documented for the C language.
I would add platform-specific code to store your settings in whatever area users of that particular platform expect. So:
For Linux: store configuration files in the location specified by $XDG_CONFIG_HOME.
For Mac: Use CFPreferences
For Windows: use the registry
Related
I have a custom board running Yocto (Jethro) and would like to run a single u-boot command, preboot. Obviously, breaking the boot sequence with space and running it manually works. How do I get it to run automatically? More specifically, where is the startup command sequence, by default?
Edit: Also, I am aware I can edit the environment at runtime. However, I am trying to build this change into the image so I can distribute it.
When you are in the uboot environment. Enter printenv, it will list the environment variables that uboot uses.
There is a variable name bootcmd. Currently, mine contain a bunch of if else command. Similarly, add your prefer function there for boot.
And after it is finished and tested. Use saveenv to store the edit
Here is a syntax for uboot.
Edit:
U-Boot allows to store commands or command sequences in a plain text file. Using the mkimage tool you can then convert this file into a script image which can be executed using U-Boot's autoscr command. U-boot Scripting Capabilities
Typically, your U-Boot recipe will build U-Boot for a single machine, in that case, I'd normally just patch the compiled in, default, U-Boot environment to do the right thing. This is achieved by
SRC_URI_machine += "file://mydefenv.patch"
Or (even better) use your own git tree. This would also have the additional benefit that your system might be able to boot up and to something useful, even if the environment would be totally corrupted.
Another possibility is to do it like Charles suggested in a comment to another answer, create an environment offline, and have U-Boot load it, see denx.de/wiki/view/DULG/UBootScripts
A third possibility, that I've also used sometimes, is to construct the environment offline (possibly using the same or a similar mechanism as in the link above), and the flash the environment to flash during the normal flash programming process. Though, most of the time I've done this on AT91's, using a tcl script similar to at91 Sam-Ba TCL script
No matter which method you chose, the bootcmd variable in U-Boot should hold your boot script.
The general answer is that bootcmd is run by default, and if there is persistent environment you can change the command and 'saveenv' so that it's kept.
It is easiest to modify the said bootcmd, which is executed anyway.
As an alternative to patching the kernel, it is possible to override the command in u-boot.
Create a file e.g. platform-top.h at the same place where you would place the patch file (it might already exist) and override the CONFIG_BOOTCOMMAND.
The result will look something like this:
/* ... */
/* replace the memory write with any other valid command */
#define CONFIG_BOOTCOMMAND "mw 0x1 0x1 && run default_bootcommand"
Don't forget to make the file known in your bbapend SRC_URI = "file://platform-top.h"
I have c program where i have to save a file in ubuntu. The program runs fine on my local pc but i want to use a single exe for other pcs whether they run linux or windows. So, how should i give path to store file that it works everywhere?
Sorry, but you can't do what you want.
When an Operating System runs a program, it looks in the file to find things that it needs to know. Windows and Linux store this information in incompatible ways, so you won't be able to create a file that will run under both Windows and Linux.
I am writing a program in C on Linux environment (Debian-Lenny) and would like the program to be updated when an update is available (the program gets notified when a new update is available). I am looking for a way that the program can update itself.
What I am thinking is that the main program invokes a new program to handle the update. The updater program will have(access to) the source code and receive the update information about the changes on the source code, something like that:
edit1: line 20, remove column 5 to 20;
edit2: line25, remove column 4-7 then add "if(x>3){" from the column4
edit3: line 26, enter a new line and insert "x++;"
then kill the main process, recompile the source code, and then replace the new binary with the old one.
or is there a better (easier) and standard way to implement the ability that a program can update itself?
I use the program to control a system with a Linux embedded board. Therefore, I don't want the source code to be accessible to another person (if the system is hacked or something).
If the best way to update a program by using the source code, how do you suggest me to secure the source code? If you suggest me to encrypt the source code, what function (Linux C) can the program use to encrypt and decrypt the source file?
If your target system is Debian, then you should just take advantage of the Debian packaging system to provide updates. Package your compiled application in a .deb package, distribute it on an APT archive which is included in your system's sources.list, and just use cron to schedule a regular update check with apt. The .deb package can include a post-installation script that restarts your application.
You could run an apt-proxy caching proxy on your "gateway" nodes that have internet access, and have the other nodes use that as their apt source.
Distributing source code in this case is probably not appropriate, because then you would need to include a full compiler toolchain on your target system.
What you're describing is very similar to the 80s-style of delivering Unix source code, popularized by the development of PERL. You use diff to get a record of changes between different versions of the source-code, then distribute this "patch" file, and use patch to perform the necessary modifications at the client-end. This doesn't address the network-communication or version-control issues.
A possible downside is that a first-time download may need to apply many patches to bring the version up. This is often the case when investigating old source from nntp:comp.sources.unix.
I am interested in programming for the Game Boy Advance using the Visual HAM IDE in C. However, every time I build a project I get a message stating:
'make.exe' is not recognized as an internal or external command,
operable program or batch file.
I downloaded GnuWin32 and make. Then, inside the ham visual editor I clicked advanced, options and set the directory of the MAKE_MODE (I guess some kind of environment variable) to the directory where the make program is.
Any suggestions on how to get this to work?
I had the same problem. Reinstall the hole vham package to the desired destination from the get-go. You can find it here: www.jharbour.com/gba/ham-280-full-win32.zip
You can't move the folders around. Even if you change the PATH variables this problem will persist.
Find where on your system the make program is in. Probably in cygwin's /usr/bin. Add that path to your system dos path.
Windows with cygwin is a screwed up hybrid system. You probably have three paths going on at once. You have the cygwin one. If you open a cygwin shell and type make I bet it finds the make program. Then if you open a dos shell ( in accessories/command prompts ) I bet it won't find the make program.
You will need to add it. Every version of windows does this differently but it is generally under right click on my computer/properties/advanced/environment variables. You will need to add it there.
And finnally there is the path known to your ide (probably). I don't know HAM, but it looks like you already did whatever they told you.
When you are done you should be able to invoke "make" from the windows/dos command prompt.
I made a program to connect to a device via Bluetooth and send the data to the web using pure C in gcc. I won't be able to implement any GUI portion in the code right now but I need to deploy it to test users for testing. I want to have the executable with an icon so that a user can click on the executable and the program starts in the terminal. How do I add an icon to the executable and start the program in the terminal?
Sorry I failed to mention before that its in Ubuntu Linux
This document explains how to add your program to the programs menu: http://standards.freedesktop.org/menu-spec/latest/.
If this is a Windows executable you're making, what you need to do is to use a resource compiler to make an object file that includes the resources you want (an icon in this case) which you can then link into your program as normal. The resource compiler I've used when building programs on Windows with gcc was called windres.
I found it to be very finicky when dealing with directories with spaces in the name. Beware!