Where can I find the string.c file itself (to read it)? - c

I'm interested in reviewing some of the functions included in the string library for c, but I can't find the source code (literally, i.e. functions and all) online and I have no idea where to find it.
Thanks.
EDIT:
the link provided by pmg shows those functions divided into c files, so it's about what I needed. Thanks.

Take a look at redhat glibc. It appears to be somewhat current.

You'll find it in the source code of the gcc compiler.
http://www.gnu.org/software/gcc/

Usually included with the compiler that you install so this may vary. Also depends on the operating system your running. If you're using windows, I recommend you run a Windows search for strings.c and if you're running linux then you can use the find command.
Disregard the file I linked to prior to this edit. I should have verified the code before sending it. It didn't apply to your question. Sorry

Maybe you're looking for GNU C string.h?

You can check the source in any standard libc implementation http://www.gnu.org/software/libc/

Related

Unable to find BLAS functions mentioned in documentation

I am currently trying to use some BLAS functions. I see the documentation and know what I want to use, but the described functions are nowhere in the actual source code in BLAS. I just don't get it.
I am trying to find blas_xmax_val. This is mentioned in the documentation on page 42. However, I do not see the function anywhere in the source folder.
If anyone has used BLAS before, please can you tell me what's going on here? Where am I supposed to look for it? It's not even mentioned in cblas.h.
This is not the only function with this problem. I see many functions mentioned in the documentation, but not in the source folder.
Please help!
I think this is the report of a technical forum that's recommending changes for BLAS that were just never adopted.
The only BLAS maximum functions I'm aware of are the IxAMAX() (x in {S,D,C,Z}) family, which return the index of the first occurrence of the maximum value.
The paper you point to is documentation for a code library created by its authors, and not a standard part of the C language. You have to get the code from them and install it, or find someone who has already done that. The code is freely available at http://netlib.org/blas/
A better-known library for doing this sort of thing is GSL, which might be easier to find an install (it's already installed on many Unix-like systems). http://www.gnu.org/software/gsl/

where to find c source code

I am a beginner in C, and i would like to read how various libraries are implemented. I looked under /usr/src/include and all i found was .h files. For example , i was looking at malloc.h and all that it does is , declare extern functions.
So i am trying to find the source for those functions. I downloaded gcc source rpm, but looking at the gcc source, it looks more like compiler code,rather than code for libraries such as stdlib.
Can you please help me by pointing me to the right direction.
Thank you.
You need to get the source code of the associated C library, probably glibc or eglibc in your case.
In the /usr/include/ folder, only the headers of the libc are present, along with some linux kernel headers in the linux/ subfolder.
You're looking for glibc, rather than gcc.
.h files never contains code (well, at least they should. Macros are exceptions)
the basic C functions are either in glibc or linux kernel
gcc, linux and glibc code are huge beasts, if you are a beginning beginner, you should go for simpler things
you probably should take a simple library, one that offer a few tools, on a narrow subject.
then go for linux and glibc (or uclibc)
I personnaly learnt many interesting stuff by reading microcontroller system libraries such as http://www.nongnu.org/avr-libc/, but this depends on what you need to do, and it requires a microcontroller to run it.
An idea: depending of what you're looking for, you could go for busybox: it is a reimplementation of many usefull system commands, you can learn a lot from it and running it do not require a dedicated computer.
Update: i asked a question related to glibc functions that got a few very interesting answers from my not-guru p.o.v:
where to find select() source code in glibc source?

Where to find stdio.h functions implementations?

I study C and I noticed that I can't find the implementation file for some header files like, for example, stdio.h which is a library which contains a lot of input/output functions, like printf. Where can I find its implementation?
Download one of these:
glibc
uclibc
dietlibc
BSD libc
Or, even better, download several of these and compare their implementations. Of course, these are likely doing a lot of things different compared to your particular standard library implementation, but would still be quite interesting for e.g. non-platform-specific functionality such as sprintf.
You need to find the source code for a C standard library like glibc: http://www.gnu.org/s/libc/
You can download the source here: http://ftp.gnu.org/gnu/glibc/
It contains source for all the library functions.
For example here. Google is your friend - just search for stdio.c. But note that you should handle these as "one implementation of many possible" - you don't know how your compiler is doing it by reading those, you just get an idea of how it can be done.
On Ubuntu or other OS that uses aptitude for package management, you can use:
apt-get source libc6
for example.
Also, running gcc in verbose mode will tell you the details of the paths it is using. This should help you find which include and library paths it's using.
gcc -v
or
gcc -Wl,--verbose
If you install the Windows SDK, there is an option to include the standard library source code, so you can also see how it is implemented on Windows.

Downloading Header Files

Where can i download the following header files for dev c
sys/types.h
sys/socket.h
netinet/in.h
arpa/inet.h
and also the structure
sockadder and it's derivatives?
I don't know why you need to download these specific files, since they should come with your compiler suite in most modern systems.
You should also keep in mind that they can be radically different depending on your platform and that those files often #include other non-standard files (which #include others and so on). This could make those files very hard to parse and understand.
That said, from some indeterminate version of Linux:
http://linux.die.net/include/sys/types.h
http://linux.die.net/include/sys/socket.h
http://linux.die.net/include/netinet/in.h
http://linux.die.net/include/arpa/inet.h
If you are going to replace missing files, consider getting/reinstalling a proper compiler suite and any developer packages your are missing.
If you want to look at the structure definitions you should definitely be looking at the documentation rather than the actual implementations. That way you avoid tying your code to private definitions e.t.c. that can change between systems.
EDIT:
Just to confirm some of my comments above, struct sockaddr for said version of Linux is defined piece-by-piece in:
http://linux.die.net/include/bits/socket.h
http://linux.die.net/include/bits/sockaddr.h
What SDK are you working with? For Linux you get these files as part of your core C sdk. For Windows it comes with the SDK as well. If you just want a quick and dirty look at some header files I use http://www.google.com/codesearch.
Those headers (not header files) are part of the implementation. They need not be real files.
If your implementation does not provide them, you're out of luck.
If your implementation provides them as real files and you deleted them, reinstalling the compiler might work.
If your implementation provides them as real files and you cannot reinstall the compiler your approach might work. Sorry, I have no idea where to download the files --- or why would anyone copy the files somewhere in the first place.
I'm assuming that you are trying to compile a source code for the *nix platform under another, such as Windows. This approach won't do you any good. Remember that you'll need the libraries of those headers and they are not portable.
Install a Virtual Machine with Ubuntu on your PC to do this kind of development.
do:
apt-get install gcc-4.2

Tool to determine symbol origin in C

I'm looking for a tool that, given a bit of C, will tell you what symbols (types, precompiler definitions, functions, etc) are used from a given header file. I'm doing a port of a large driver from Solaris to Windows and figuring out where things are coming from is getting to be difficult, so this would be a huge help. Any ideas?
Edit: Not an absolute requirement, but tools that work on Windows would be a plus.
Edit #2: To clarify what I'm trying to do, I have a codebase I'm trying to port, which brings in a large number of headers. What I'd like is a tool that, given foo.c, will tell me which symbols it uses from bar.h.
I like KScope, which copes with very large projects.
KScope http://img110.imageshack.us/img110/4605/99101zd3.png
I use on both Linux and Windows :
gvim + ctags + cscope.
Same environment will work on solaris as well, but this is of course force you to use vim as editor, i pretty sure that emacs can work with both ctags and cscope as well.
You might want give a try to vim, it's a bit hard at first, but soon you can't work another way. The most efficient editor (IMHO).
Comment replay:
Look into the cscope man:
...
Find functions called by this function:
Find functions calling this function:
...
I think it's exactly what are you looking for ... Please clarify if not.
Comment replay 2:
ok, now i understand you. The tools i suggested can help you understand code flow, and find there certain symbol is defined, but not what are you looking for.
Not what you asking for but since we are talking i have some experience with porting and drivers (feel free to ignore)
It seems like compiler is good enough for your task. You just starting with original file and let compiler find what missing part, it will be a lot of empty stubs and you will get you code compiled.
At least for beginning i suggest you to create a lot of stubs and modifying original code as less as possible, later on once you get it working you can optimize.
It's might be more complex depending on the type of driver your are porting (I'm assuming kernel driver), the Windows and Solaris subsystems are not so alike. We do have a driver working on both solaris and windows, but it was designed to be multi platform from the beginning.
emacs and etags.
And I leverage make to run the tag indexing for me---that way I can index a large project with one command. I've been thinking about building a master index and separate module indecies, but haven't gotten around to implementing this yet...
#Ilya: Would pistols at dawn be acceptable?
Try doxygen, it can produce graphs and/or HTML and highly customizable

Resources