Concatinating a file in C (without stdio.h etc.)

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
JaMiE P
Posts: 7
Joined: Sat Mar 26, 2005 12:00 am

Concatinating a file in C (without stdio.h etc.)

Post by JaMiE P »

Hi all,
So yeah. Is it possible?

EDIT:Never mind. I'll just de-compile cat.
Da_Maestro
Member
Member
Posts: 144
Joined: Tue Oct 26, 2004 11:00 pm
Location: Australia

Re: Concatinating a file in C (without stdio.h etc.)

Post by Da_Maestro »

Perhaps you should elaborate more on your question. What is it exactly that you are trying to do?

Give us an example in C using stdio.h
Two things are infinite: The universe and human stupidity. But I'm not quite sure about the universe.
--- Albert Einstein
User avatar
carbonBased
Member
Member
Posts: 382
Joined: Sat Nov 20, 2004 12:00 am
Location: Wellesley, Ontario, Canada
Contact:

Re: Concatinating a file in C (without stdio.h etc.)

Post by carbonBased »

There're tons of ways, assuming you've implemented some form of file i/o of your own, external to stdio.h.

Or, technically, you can just "extern" all the stdio functions, still use them, but not include stdio.h :)

Or, if you're really just looking for a C solution (and not an OSDev solution) then just exec a shell command of "cat file1 file2 > file3" or "copy file1+file2 file3" depending on your OS.

--Jeff
JaMiE P
Posts: 7
Joined: Sat Mar 26, 2005 12:00 am

Re: Concatinating a file in C (without stdio.h etc.)

Post by JaMiE P »

I mean by creating a function/command that would concatinate (like most people's second program next to Hello World or the UNIX command cat) a file by using ASM, and then letting me call it from my program, like this (for an OS):
Part 1

Code: Select all

{
    blah
    blah
    blah
    f_concat("file.txt")
}
And then having this bit:

Code: Select all

unsigned int f_concat(char *message, unsigned int line)
{
     I need the code which goes here
}
Thanks,
JaMiE P
Creator, Phelansys OS[/u]
User avatar
carbonBased
Member
Member
Posts: 382
Joined: Sat Nov 20, 2004 12:00 am
Location: Wellesley, Ontario, Canada
Contact:

Re: Concatinating a file in C (without stdio.h etc.)

Post by carbonBased »

The problem is (and what I was hinting at) is that if this is intended for a OS in development, you're going to need a basic kernel and IO driver/module before doing this, and even with both those, there is no standard way -- every OS is different.

That's the whole point of the libc and the stdio.h header file you mention. It provides a basic and portable way to do these things on all OSs. If you wish to circumvent this, then you're on your own. You'll need to look into the different devices you want to support (IDE? SCSI? ATAPI? etc) and write drivers for those, and some interface that will allow you do create such a 'cat'-like program.

Cheers,
Jeff
DruG5t0r3
Member
Member
Posts: 29
Joined: Thu Mar 24, 2005 12:00 am
Contact:

Re: Concatinating a file in C (without stdio.h etc.)

Post by DruG5t0r3 »

again, those are OS dependant. Before implementing anything like that, you would need to design and code an IPC. doing stuff like cat bla | grep blah is done through pipes in linux I believe (correct me if i'm wrong)
[AlAdDiN]
Member
Member
Posts: 107
Joined: Fri Oct 22, 2004 11:00 pm
Contact:

Re: Concatinating a file in C (without stdio.h etc.)

Post by [AlAdDiN] »

if you are trying to write a concat function for your own OS, you have to write some I/O primitives first ...
assuming you have some functions that read file to a given memory addresse and write it from a given address, all you have to do is to copy both file in two memory adresses, create a new file and write the content of the two memory areas into it

but there is no "magic" methode to do it without any I/O methode
-----------------------
There are 10 types of people in this world... those that understand binary, and those that don't.
Post Reply