home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / TURBO_C / TC_BUG.ZIP / TESTOPEN.C next >
Encoding:
C/C++ Source or Header  |  1980-01-01  |  2.5 KB  |  82 lines

  1.  
  2. /*********************************************************************/
  3. /* The following shows a bug in TURBO-C _open function.              */
  4. /*                                                                   */
  5. /* _open will work only with an existing file even O_CREAT specified */
  6. /* open works correctly though                                       */
  7. /*                                                                   */
  8. /* Example:  copy testopen.exe test                                  */
  9. /*           testopen test                                           */
  10. /*                                                                   */
  11. /*   first "_open" call will be O.K.,  but 2nd _open will be fail    */
  12. /*   since "test" is deleted.  On the other hand, "open" will be     */
  13. /*   O.K. all time.                                                  */
  14. /*                                                                   */
  15. /*                                                                   */
  16. /* If you know any fix for this bug, please let me know at C-STATION */
  17. /* 612-938-4809.                                                     */
  18. /*                                     Li Su                         */
  19. /*********************************************************************/
  20.  
  21.  
  22. #include <stdio.h>
  23. #include <fcntl.h>
  24. #include <sys\stat.h>
  25.  
  26. main(argc, argv)
  27. int     argc;
  28. char    *argv[];
  29.  
  30.     {
  31.     
  32.     int    fp;
  33.  
  34.     if (argc < 2) {
  35.           printf("USAGE: testopen pathname\n");
  36.           exit(1);
  37.           }
  38.  
  39.         /* test _open */
  40.  
  41.     if ((fp=_open(argv[1], O_RDWR|O_CREAT, S_IREAD|S_IWRITE)) != -1) {
  42.           printf("_open: OK.  fp = %d\n", fp);
  43.           _close(fp);
  44.           unlink(argv[1]);
  45.           }
  46.         else
  47.           perror("_open");
  48.  
  49.  
  50.         /* test open */
  51.  
  52.     if ((fp=open(argv[1], O_RDWR|O_CREAT, S_IREAD|S_IWRITE)) != -1) {
  53.           printf("open: OK.  fp = %d\n", fp);
  54.           close(fp);
  55.           unlink(argv[1]);
  56.           }
  57.         else
  58.           perror("open");
  59.  
  60.  
  61.         /* test _open again*/
  62.  
  63.     if ((fp=_open(argv[1], O_RDWR|O_CREAT, S_IREAD|S_IWRITE)) != -1) {
  64.           printf("_open: still OK.  fp = %d\n", fp);
  65.           _close(fp);
  66.           unlink(argv[1]);
  67.           }
  68.         else
  69.           perror("2nd _open");
  70.  
  71.  
  72.         /* test open again */
  73.  
  74.     if ((fp=open(argv[1], O_RDWR|O_CREAT, S_IREAD|S_IWRITE)) != -1) {
  75.           printf("open: still OK.  fp = %d\n", fp);
  76.           close(fp);
  77.           unlink(argv[1]);
  78.           }
  79.         else
  80.           perror("2nd open");
  81.  
  82.     }