This is the mail archive of the cygwin@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Removing the same file from two consoles


Here is some program which was invocated on two consoles.


The program behavior is different on
 * Cygwin, DJGPP on the one hand
   and
 * Mingw on the other hand
 environments.


Which is right/correct/preferable?


========= C-code : BEGIN =========
/* File t.c */

#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <assert.h>

int main(int argc, char** argv)
{
int  rc;
char ch;
FILE* fp;
int i;

  assert (argc > 1);

  printf ("Command line : ");
  for (i = 0; i < argc; i++) printf ("%s ", argv[i]);
  printf ("\n");

  errno = 0;
  rc = access (argv[1], F_OK);
  printf ("access : rc = %d; errno = %u (%s)\n", rc, errno, strerror(errno));

  errno = 0;
  rc = remove (argv[1]);
  printf ("remove : rc = %d; errno = %u (%s)\n", rc, errno, strerror(errno));

  fp = fopen (argv[1], "w");
  printf ("fopen  : %s\n", (fp ? "OK" : "FAILURE"));

  printf ("Enter any key : ");
  scanf ("%c", &ch);

  errno = 0;
  rc = access (argv[1], F_OK);
  printf ("access : rc = %d; errno = %u (%s)\n", rc, errno, strerror(errno));

  printf ("Thanks. Bye\n");

  return 0;
}

========= C-code : END ===========






######### Run via Cygwin : BEGIN #########
=========================================
Windows 2000
CYGWIN_NT-5.0 1.3.22(0.78/3/2)
GNU gcc version 3.2 20020927 (prerelease)
=========================================


====================================
Step 0. Compiling and getting status
====================================
------ Console-0 ------
$ gcc t.c -o progc
-----------------------


=================================================
Step 1. removing and fopening a file on Console-1
=================================================
------ Console-1 ------
$ progc foo
Command line : progc foo
access : rc = -1; errno = 2 (No such file or directory)
remove : rc = -1; errno = 2 (No such file or directory)
fopen  : OK
Enter any key :
-----------------------


========================================================
Step 2. removing and fopening the same file on Console-2
========================================================
------ Console-2 ------
$ progc foo
Command line : progc foo
access : rc = 0; errno = 0 (No error)
remove : rc = 0; errno = 0 (No error)
fopen  : FAILURE
Enter any key :
-----------------------


======================================
Step 3. Entering some key on Console-2
======================================
------ Console-2 ------
----- continuation ----
Enter any key : a
access : rc = -1; errno = 13 (Permission denied)
Thanks. Bye
-----------------------


======================================
Step 4. Entering some key on Console-1
======================================
------ Console-1 ------
----- continuation ----
Enter any key : b
access : rc = -1; errno = 2 (No such file or directory)
Thanks. Bye
-----------------------


######### Run via Cygwin : END ###########






######### Run via Mingw : BEGIN #########
====================
Windows 2000
MinGW 2.0.0.-2
GNU gcc version 3.2
===================



====================================
Step 0. Compiling and getting status
====================================
------ Console-0 ------
$ gcc t.c -o progm
-----------------------


=================================================
Step 1. removing and fopening a file on Console-1
=================================================
------ Console-1 ------
$ progm foo
Command line : progm.exe foo
access : rc = -1; errno = 2 (No such file or directory)
remove : rc = -1; errno = 2 (No such file or directory)
fopen  : OK
Enter any key :
-----------------------


========================================================
Step 2. removing and fopening the same file on Console-2
========================================================
------ Console-2 ------
$ progm foo
Command line : progm.exe foo
access : rc = 0; errno = 0 (No error)
remove : rc = -1; errno = 13 (Permission denied)
fopen  : OK
Enter any key :
-----------------------


======================================
Step 3. Entering some key on Console-2
======================================
------ Console-2 ------
----- continuation ----
Enter any key : a
access : rc = 0; errno = 0 (No error)
Thanks. Bye
-----------------------


======================================
Step 4. Entering some key on Console-1
======================================
------ Console-1 ------
----- continuation ----
Enter any key : b
access : rc = 0; errno = 0 (No error)
Thanks. Bye
-----------------------


######### Run via Mingw : END ###########


   =====================================
   Alex Vinokur
     mailto:alexvn@connect.to
     http://mathforum.org/library/view/10978.html
   =====================================








--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]