pastebin - collaborative debugging tool
nrubsig.kpaste.net RSS


wincreatetempfile1.c - Cygwin FILE_ATTRIBUTE_TEMPORARY test
Posted by Anonymous on Wed 17th Apr 2024 00:52
raw | new post

  1.  
  2. /*
  3.  * wincreatetempfile1.c - Cygwin FILE_ATTRIBUTE_TEMPORARY test
  4.  *
  5.  * Usage:
  6.  * $ gcc -Wall wincreatetempfile1.c -o wincreatetempfile1
  7.  * $ rm -f xxx ; ./wincreatetempfile1 xxx yyy zzz 000 111 ; cat -n xxx
  8.  * ./wincreatetempfile1: h=0x0x150
  9.  * ./wincreatetempfile1: fd 3
  10.  *      1  yyyzzz000111
  11.  *
  12.  * Written by Roland Mainz <roland.mainz@nrubsig.org>
  13.  */
  14.  
  15. #include <windows.h>
  16. #include <stdio.h>
  17. #include <fcntl.h>
  18. #include <unistd.h>
  19. #include <sys/cygwin.h>
  20.  
  21. int main(int ac, char *av[])
  22. {
  23.     HANDLE h = CreateFile(
  24.         av[1],
  25.         GENERIC_READ | GENERIC_WRITE,
  26.         0,
  27.         NULL,
  28.         CREATE_NEW,
  29.         FILE_ATTRIBUTE_TEMPORARY,
  30.         NULL);
  31.  
  32.     if (h == INVALID_HANDLE_VALUE) {
  33.         DWORD err = GetLastError();
  34.         (void)fprintf(stderr, "%s: error %d\n", av[0], err);
  35.         return 1;
  36.     }
  37.  
  38.     (void)printf("%s: h=0x%p\n", av[0], (void *)h);
  39.  
  40.     int fd = cygwin_attach_handle_to_fd(av[1], -1, h, 1, O_RDWR);
  41.  
  42.     (void)printf("%s: fd %d\n", av[0], fd);
  43.     for(int i = 2 ; i < ac ; i++) {
  44.         (void)write(fd, av[i], strlen(av[i]));
  45.     }
  46.    
  47.     (void)close(fd);
  48.  
  49.     return 0;
  50. }

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with {%HIGHLIGHT}




All content is user-submitted.
The administrators of this site (kpaste.net) are not responsible for their content.
Abuse reports should be emailed to us at