Unix Programming - Newbie Question - Help with design

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > January 2004 > Newbie Question - Help with design





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Newbie Question - Help with design
Jamie

2004-01-23, 5:18 pm



Hello,

I am studying the C language, and I work mostly with FreeBSD at my job.
I need to write a program which will check all of the files in a
directory, and if one is over 20 megs, I need to compress it and move it
to an archive directory.

I realize that it would be very easy to do this with a shell script,
but since I am studying C, I would like to make a C program to do the job
for the coding practice.

Most of the program is simple, but I don't know what to do about the
compression part. Easy to do with gzip, but, like I say, I'd like to be
able to do this in my program.

Can anyone offer some suggestions as to how I would go about this?
Maybe it's best if I just write the shell program, though I would really
like to start doing C work at the office.


Thanks!


- Jamie






Greetings from Minneapolis, MN, United States

"A friend is someone who lets you have total freedom to be yourself."

Mike Chirico

2004-01-23, 5:18 pm


"Jamie" <jamie@gnulife.org> wrote in message
news:20031212190126.L96527-100000@floyd.gnulife.org...
quote:

>
>
> Hello,
>
> I am studying the C language, and I work mostly with FreeBSD at my job.
> I need to write a program which will check all of the files in a
> directory, and if one is over 20 megs, I need to compress it and move it
> to an archive directory.
>
> I realize that it would be very easy to do this with a shell script,
> but since I am studying C, I would like to make a C program to do the job
> for the coding practice.



Well, for the people who have to uncompress that data, I'd recommend calling
the "zlib" library from your C program.

http://www.gzip.org/zlib/

Take a look at minigzip.c in the download, which does it all. It can be
compiled as follows:

gcc minigzip.c -lz -o minigzip

And, anyone who has to use the files can just "gunzip" them; which will
probably keep them happy.

Regards,

Mike Chirico



=?iso-8859-1?q?M=E5ns_Rullg=E5rd?=

2004-01-23, 5:18 pm

"Mike Chirico" <mchirico@comcast.net> writes:
quote:

> "Jamie" <jamie@gnulife.org> wrote in message
> news:20031212190126.L96527-100000@floyd.gnulife.org...
>
> Well, for the people who have to uncompress that data, I'd recommend calling
> the "zlib" library from your C program.



Why not just system("gzip ...")? You might want to learn zlib, of course.

--
Måns Rullgård
mru@kth.se
Jamie

2004-01-23, 5:18 pm

On Sat, 13 Dec 2003, [iso-8859-1] M=E5ns Rullg=E5rd wrote:
quote:

> "Mike Chirico" <mchirico@comcast.net> writes:
>
job.[QUOTE][color=darkred]
it[QUOTE][color=darkred]
,[QUOTE][color=darkred]
job[QUOTE][color=darkred]
lling[QUOTE][color=darkred]
>
> Why not just system("gzip ...")? You might want to learn zlib, of course=


=2E
quote:

>



I considered it, but I'd like to try including the compression library
in my program for the experience. I am going to take a look at the info
Mike Chirico sent and see if I can use some of that code in my program.
Thanks for the suggestion,


- Jamie





Greetings from Minneapolis, MN, United States

"A friend is someone who lets you have total freedom to be yourself."


Konstantinos Peletidis

2004-01-23, 5:18 pm

On Sat, 13 Dec 2003 03:21:12 +0100
mru@kth.se (M=E5ns Rullg=E5rd) wrote:
quote:

> "Mike Chirico" <mchirico@comcast.net> writes:
>=20
>=20
> Why not just system("gzip ...")? You might want to learn zlib, of
> course.



Hello,

I don't think using system(3) is a good idea. Especially if there is a
chance the program you are writing is going to be given suid or sgid
privileges.

Quoting from the Linux man page of system(3):

<QUOTE>

Do not use system() from a program with suid or sgid priv-
ileges, because strange values for some environment vari-
ables might be used to subvert system integrity. Use the
exec(3) family of functions instead, but not execlp(3) or
execvp(3).

</QUOTE>


Just my 2 eurocents

--=20
Konstantinos Peletidis
Electronic & Computer Engineer
Please remove strings "foo" and "bar" from my address before sending me
mail.
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com