Connecting Tech Pros Worldwide Forums | Help | Site Map

Q: portable way copy files using C on Unix an Windows -- dirent or similar

**--> That Guy Downstairs
Guest
 
Posts: n/a
#1: Feb 7 '06
What files are needed to be #included to be able to copy files to a new
directory and be portable?
ie. use it in Unix (SGI and Linux) or Windows 2000.
#ifdefs Ok.

using dirent.h on SGI, but it's not working on Windows w/ VS6.0.

Thanks.



Nelu
Guest
 
Posts: n/a
#2: Feb 7 '06

re: Q: portable way copy files using C on Unix an Windows -- dirent or similar


**--> That Guy Downstairs <--** wrote:[color=blue]
> What files are needed to be #included to be able to copy files to a new
> directory and be portable?
> ie. use it in Unix (SGI and Linux) or Windows 2000.
> #ifdefs Ok.
>
> using dirent.h on SGI, but it's not working on Windows w/ VS6.0.
>
> Thanks.
>
>[/color]
There's no standard way to do that. You may be able to use
gtk+ or something similar to do that in C (or QT/wxWidgets
for C++).
The standard C has no idea of what a directory is, even.

--
Ioan - Ciprian Tandau
tandau _at_ freeshell _dot_ org (hope it's not too late)
(... and that it still works...)
Nelu
Guest
 
Posts: n/a
#3: Feb 7 '06

re: Q: portable way copy files using C on Unix an Windows -- dirent or similar


**--> That Guy Downstairs <--** wrote:
<snip>[color=blue]
> using dirent.h on SGI, but it's not working on Windows w/ VS6.0.[/color]

This is POSIX. It's not supposed to work on Windows. However,
you can compile the sources on Windows using mingw or
cygwin and it will work. I'm not sure how the dependency
works under those, though.

--
Ioan - Ciprian Tandau
tandau _at_ freeshell _dot_ org (hope it's not too late)
(... and that it still works...)
Flash Gordon
Guest
 
Posts: n/a
#4: Feb 7 '06

re: Q: portable way copy files using C on Unix an Windows -- dirent or similar


**--> That Guy Downstairs <--** wrote:[color=blue]
> What files are needed to be #included to be able to copy files to a new
> directory and be portable?
> ie. use it in Unix (SGI and Linux) or Windows 2000.
> #ifdefs Ok.
>
> using dirent.h on SGI, but it's not working on Windows w/ VS6.0.[/color]

The C standard knows nothing about directories, so you can't do this in
standard C which is the topic of this group.

I would recommend you write a POSIX routine for the POSIX like systems
(including Linux) and a Windows routine for Windows, then set up your
build systems so that the appropriate routine is built on each system.
Isolate all such routines from the rest of your code, then at least the
bulk of your code is common and portable.

The details of the specific routines, and how to configure your build
environments, are off topic here.
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
Default User
Guest
 
Posts: n/a
#5: Feb 7 '06

re: Q: portable way copy files using C on Unix an Windows -- dirent or similar


**--> That Guy Downstairs wrote:
[color=blue]
> What files are needed to be #included to be able to copy files to a
> new directory and be portable? ie. use it in Unix (SGI and Linux) or
> Windows 2000. #ifdefs Ok.[/color]

The only really portable way is to open the original for reading, open
the destination for writing, and copy the data. There are no facilities
for creating directories though, so if by "new directory" you mean one
that you've just made that may not work either

Anything else is implemenation-specific.



Brian
Richard Heathfield
Guest
 
Posts: n/a
#6: Feb 7 '06

re: Q: portable way copy files using C on Unix an Windows -- dirent or similar


Flash Gordon said:
[color=blue]
> **--> That Guy Downstairs <--** wrote:[color=green]
>> What files are needed to be #included to be able to copy files to a new
>> directory and be portable?
>> ie. use it in Unix (SGI and Linux) or Windows 2000.
>> #ifdefs Ok.
>>
>> using dirent.h on SGI, but it's not working on Windows w/ VS6.0.[/color]
>
> The C standard knows nothing about directories, so you can't do this in
> standard C which is the topic of this group.[/color]

By the same logic, the C standard knows nothing about users, groups, and
permissions in NT domains, so I can't write a standard C program to
generate ACL scripts for migrating users from one domain to another. And
yet I have written just such a program.

The "knows nothing" terminology so beloved of comp.lang.c regulars is
woefully broken. Oxymoronically, we need a new cliche.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Kenny McCormack
Guest
 
Posts: n/a
#7: Feb 8 '06

re: Q: portable way copy files using C on Unix an Windows -- dirent or similar


In article <dsb5ar$r1j$1@nwrdmz01.dmz.ncs.ea.ibs-infra.bt.com>,
Richard Heathfield <invalid@invalid.invalid> wrote:
....[color=blue]
>By the same logic, the C standard knows nothing about users, groups, and
>permissions in NT domains, so I can't write a standard C program to
>generate ACL scripts for migrating users from one domain to another. And
>yet I have written just such a program.[/color]

Be careful. You're posting sense in a nonsense newsgroup.
Your fellow regulars might desert you.
And then where will you be?
[color=blue]
>The "knows nothing" terminology so beloved of comp.lang.c regulars is
>woefully broken. Oxymoronically, we need a new cliche.[/color]

Well put.

I also think we need a terminology that avoids the absurd statement that
something that is obviously C, but which includes functions, etc that are
not in the standard is "not C" (when it obviously is C - do I have to
elaborate this any further?).

Flash Gordon
Guest
 
Posts: n/a
#8: Feb 8 '06

re: Q: portable way copy files using C on Unix an Windows -- dirent or similar


Richard Heathfield wrote:[color=blue]
> Flash Gordon said:
>[color=green]
>> **--> That Guy Downstairs <--** wrote:[color=darkred]
>>> What files are needed to be #included to be able to copy files to a new
>>> directory and be portable?
>>> ie. use it in Unix (SGI and Linux) or Windows 2000.
>>> #ifdefs Ok.
>>>
>>> using dirent.h on SGI, but it's not working on Windows w/ VS6.0.[/color]
>> The C standard knows nothing about directories, so you can't do this in
>> standard C which is the topic of this group.[/color]
>
> By the same logic, the C standard knows nothing about users, groups, and
> permissions in NT domains, so I can't write a standard C program to
> generate ACL scripts for migrating users from one domain to another. And
> yet I have written just such a program.[/color]

Yes, but a script is a file, and standard C can manipulate files. Based
on what the OP says (mention of using dirent) he is actually reading the
directory.
[color=blue]
> The "knows nothing" terminology so beloved of comp.lang.c regulars is
> woefully broken. Oxymoronically, we need a new cliche.[/color]

Well, if you can suggest a better phrase feel free.
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
Richard Heathfield
Guest
 
Posts: n/a
#9: Feb 8 '06

re: Q: portable way copy files using C on Unix an Windows -- dirent or similar


Flash Gordon said:
[color=blue]
> Richard Heathfield wrote:[color=green]
>> Flash Gordon said:
>>[color=darkred]
>>> **--> That Guy Downstairs <--** wrote:
>>>> What files are needed to be #included to be able to copy files to a new
>>>> directory and be portable?
>>>> ie. use it in Unix (SGI and Linux) or Windows 2000.
>>>> #ifdefs Ok.
>>>>
>>>> using dirent.h on SGI, but it's not working on Windows w/ VS6.0.
>>> The C standard knows nothing about directories, so you can't do this in
>>> standard C which is the topic of this group.[/color]
>>
>> By the same logic, the C standard knows nothing about users, groups, and
>> permissions in NT domains, so I can't write a standard C program to
>> generate ACL scripts for migrating users from one domain to another. And
>> yet I have written just such a program.[/color]
>
> Yes, but a script is a file, and standard C can manipulate files. Based
> on what the OP says (mention of using dirent) he is actually reading the
> directory.[/color]

I'm not arguing that the OP's requirement can be solved portably. I'm only
arguing that C's "ignorance" of a subject does not, /per se/, make that
subject off-topic.
[color=blue]
>[color=green]
>> The "knows nothing" terminology so beloved of comp.lang.c regulars is
>> woefully broken. Oxymoronically, we need a new cliche.[/color]
>
> Well, if you can suggest a better phrase feel free.[/color]

Nothing as terse springs to mind, alas. Unless someone comes up with a
suitable replacement, we may simply have to accept that sometimes the
choice is between "wrong" and "long". Of the two, I prefer "long".

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
SM Ryan
Guest
 
Posts: n/a
#10: Feb 8 '06

re: Q: portable way copy files using C on Unix an Windows -- dirent or similar


"**--> That Guy Downstairs <--**" <atf_eng@yahoo.com> wrote:
# What files are needed to be #included to be able to copy files to a new
# directory and be portable?
# ie. use it in Unix (SGI and Linux) or Windows 2000.
# #ifdefs Ok.
#
# using dirent.h on SGI, but it's not working on Windows w/ VS6.0.
#
# Thanks.
#
#
#
#

--
SM Ryan http://www.rawbw.com/~wyrmwif/
This is one wacky game show.
SM Ryan
Guest
 
Posts: n/a
#11: Feb 8 '06

re: Q: portable way copy files using C on Unix an Windows -- dirent or similar


"**--> That Guy Downstairs <--**" <atf_eng@yahoo.com> wrote:
# What files are needed to be #included to be able to copy files to a new
# directory and be portable?
# ie. use it in Unix (SGI and Linux) or Windows 2000.
# #ifdefs Ok.

You might consider something other than C, like Tcl or Perl.
In Tcl, you can do this portably in a few dozen lines. I expect
Perl to be as easy.

--
SM Ryan http://www.rawbw.com/~wyrmwif/
This is one wacky game show.
Old Wolf
Guest
 
Posts: n/a
#12: Feb 8 '06

re: Q: portable way copy files using C on Unix an Windows -- dirent or similar


**--> That Guy Downstairs <--** wrote:
[color=blue]
> What files are needed to be #included to be able to copy files to a new
> directory and be portable?
> ie. use it in Unix (SGI and Linux) or Windows 2000.
> #ifdefs Ok.
>
> using dirent.h on SGI, but it's not working on Windows w/ VS6.0.[/color]

Upgrade your compiler? All the windows compilers I've ever used
provide the common unix functions (dirent.h etc).

Jack Klein
Guest
 
Posts: n/a
#13: Feb 8 '06

re: Q: portable way copy files using C on Unix an Windows -- dirent or similar


On 7 Feb 2006 18:18:06 -0800, "Old Wolf" <oldwolf@inspire.net.nz>
wrote in comp.lang.c:
[color=blue]
> **--> That Guy Downstairs <--** wrote:
>[color=green]
> > What files are needed to be #included to be able to copy files to a new
> > directory and be portable?
> > ie. use it in Unix (SGI and Linux) or Windows 2000.
> > #ifdefs Ok.
> >
> > using dirent.h on SGI, but it's not working on Windows w/ VS6.0.[/color]
>
> Upgrade your compiler? All the windows compilers I've ever used
> provide the common unix functions (dirent.h etc).[/color]

You haven't looked at quite enough Windows compilers. It's been
absent from Microsoft's Visual C++ since at least 6.0. The features
are quite easy to implement on top of the Win32 API, and every other
compiler that I know of for Win32 does so.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Rod Pemberton
Guest
 
Posts: n/a
#14: Feb 8 '06

re: Q: portable way copy files using C on Unix an Windows -- dirent or similar



"**--> That Guy Downstairs <--**" <atf_eng@yahoo.com> wrote in message
news:IuBz1M.9DF@news.boeing.com...[color=blue]
> What files are needed to be #included to be able to copy files to a new
> directory and be portable?
> ie. use it in Unix (SGI and Linux) or Windows 2000.
> #ifdefs Ok.
>
> using dirent.h on SGI, but it's not working on Windows w/ VS6.0.[/color]

I don't have a working solution for you. But, I have a place you can start.
Doug Gwyn's libndir. The file I have is called: libndir-posix.tar.Z. It
contains C code to add dirent and 'friends' to POSIX like OS's. You'll need
to do some porting.


Rod Pemberton


S7Solutions
Guest
 
Posts: n/a
#15: Feb 21 '06

re: Q: portable way copy files using C on Unix an Windows -- dirent or similar


Hi there

There is no one standard answer for this - it's a ocean of porting to
do but again depends on what and how much compatibility you are
expecting. If you want you can contact us for a free technical road map
for porting.

Manjunath M
S7 Software Solutions
Re-Defining Cross-Platform Porting & Migration
www.S7SOlutions.com

Closed Thread