ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
i am writing a quick C code that will read a text file that contains a list of files. my program will then be performing sha256sum on each file listing and writing that to an output file.
what i'd like to do is incorporate the source code of sha256sum from coreutils into my program, so that there can be no doubt about the integrity of the checksum... rather than referencing /usr/bin/sha256sum which may or may not be on a system.
I have the source from coreutils and i see under its lib folder the file sha256sum.c. however not sure what function to reference out of that file, or if there's another wrapper file i should be referencing?
Just save the above file somewhere and make it executable ( chmod +x ) and run it like ( presumuing you are in the same directory as the file itself ) so:
This will print the generated sha and verivy with the sha256sum command.
This as you can see from the gcc line links against openssl, this will be better than embeding all the code in your application as most (all?) linux distro are going to have openssl installed and when openssl is updated your code will benifit from the updated lib.
thanks Keith.
your code worked provided i strip out the stuff at the top between #if 0 and #endif, and compile my own executable... which is fine for me. it linked with -lssl and the 60 character hash output matches that from /usr/bin/sha256sum.
when i try to run it as you described, i get "Illegal variable name"
I compiled it using gcc sha256.c -O2 -o sha256_kh -lssl.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.