This is the mail archive of the 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]

Re: [Patch] unlink

Pierre A. Humblet schrieb:
It works on normal files. I haven't tested with the
special names because I forgot how to create them !
Feedback welcome.

works fine on w2k. attached is a test to create such files. unlink works fine on these.

didn't test with wchar and unicode files yet, just char.
but coreutils/findutils don't work with unicode files anyway.
(just testing findutils-4.1.20)

On reflection, however, wouldn't it be a little easier just to prepend
the path being deleted with a: \\.\ so that "rm nul" would eventually
translate to DeleteFile("\\.\c:\foo\null") (I'm not using true C
backslash quoting here)?  I don't know if that would work on Windows 9x,
// c++ -I../src/winsup/cygwin -o testcreate -lntdll 
#include "winsup.h"
#include <stdio.h>
#include <ntdef.h>
#include "ntdll.h"

//#define NTCREATE

    OUT PHANDLE  DirectoryHandle,
    IN ACCESS_MASK  DesiredAccess,
    IN POBJECT_ATTRIBUTES  ObjectAttributes

#ifndef NTCREATE
static HANDLE
create (char *path)
  HANDLE hFile; 
  char pwd[CYG_MAX_PATH], dev[CYG_MAX_PATH];
  int len;

  //create ("\\\\.\\c:\\con");
  if (len = GetCurrentDirectoryA (CYG_MAX_PATH, pwd)) {
    strcpy(dev, "\\\\.\\");
    strcat(dev, pwd);
    strcat(dev, "\\");
    strcat(dev, path);
  hFile = CreateFile(dev,     // file to create
		     GENERIC_WRITE,          // open for writing
		     0,                      // do not share
		     NULL,                   // default security
		     CREATE_ALWAYS,          // overwrite existing
		     FILE_ATTRIBUTE_NORMAL | // normal file
		     FILE_FLAG_OVERLAPPED,   // asynchronous I/O
		     NULL);                  // no attr. template
  if (hFile == INVALID_HANDLE_VALUE) return 0;
  printf("%s created\n", path);
  return hFile;

static HANDLE
nt_create (WCHAR *wpath)
  UNICODE_STRING upath = {0, sizeof (wpath), wpath};
  //UNICODE_STRING cpath = {0, 2, L"."};

  int len;
  HANDLE x, root = NULL;
  NTSTATUS status;
  if (len = GetCurrentDirectoryW (2*CYG_MAX_PATH, pwd)) {
    UNICODE_STRING upwd = {0, sizeof (pwd), pwd};
    InitializeObjectAttributes (&attr, &upwd, OBJ_CASE_INSENSITIVE, NULL, NULL);
    NtOpenFile(&root, STANDARD_RIGHTS_ALL, &attr, &io, 0, 0);
  InitializeObjectAttributes (&attr, &upath, OBJ_CASE_INSENSITIVE, root, NULL);
  status = NtCreateFile (&x, STANDARD_RIGHTS_ALL, &attr, &io, NULL, FILE_ATTRIBUTE_NORMAL, 
                         FILE_SHARE_READ, FILE_OPEN, FILE_DELETE_ON_CLOSE, NULL, 0);
  if (!NT_SUCCESS (status))
      printf("error creating %ls\n", wpath);
      return 0;
  else {
    return x;

int main(int argc, char** argv)
#ifndef NTCREATE
  create ("con");
  create ("com");
  create ("nul");
  create ("aux");
  create ("prn");
  create ("lpt1");
  create ("...");
  nt_create (L"con");
  nt_create (L"nul");
  nt_create (L"aux");
  nt_create (L"prn");
  nt_create (L"lpt1");
  nt_create (L"...");

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