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

  • Thread starter **--> That Guy Downstairs
  • Start date
T

**--> That Guy Downstairs

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.
 
N

Nelu

**--> That Guy Downstairs <--** said:
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.
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.
 
N

Nelu

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

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.
 
F

Flash Gordon

**--> That Guy Downstairs <--** said:
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.

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.
 
D

Default User

**--> That Guy Downstairs said:
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.

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
 
R

Richard Heathfield

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

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.
 
F

Flash Gordon

Richard said:
Flash Gordon said:


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.

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.
The "knows nothing" terminology so beloved of comp.lang.c regulars is
woefully broken. Oxymoronically, we need a new cliche.

Well, if you can suggest a better phrase feel free.
 
K

Kenny McCormack

Richard Heathfield said:
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.

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

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?).
 
R

Richard Heathfield

Flash Gordon said:
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.

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.
Well, if you can suggest a better phrase feel free.

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".
 
S

SM Ryan

# 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.
#
#
#
#
 
S

SM Ryan

# 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.
 
O

Old Wolf

**--> That Guy Downstairs <--** said:
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.

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

Jack Klein

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

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.
 
R

Rod Pemberton

**--> That Guy Downstairs said:
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.

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
 
S

S7Solutions

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top