home *** CD-ROM | disk | FTP | other *** search
-
- /*********************************************************************/
- /* The following shows a bug in TURBO-C _open function. */
- /* */
- /* _open will work only with an existing file even O_CREAT specified */
- /* open works correctly though */
- /* */
- /* Example: copy testopen.exe test */
- /* testopen test */
- /* */
- /* first "_open" call will be O.K., but 2nd _open will be fail */
- /* since "test" is deleted. On the other hand, "open" will be */
- /* O.K. all time. */
- /* */
- /* */
- /* If you know any fix for this bug, please let me know at C-STATION */
- /* 612-938-4809. */
- /* Li Su */
- /*********************************************************************/
-
-
- #include <stdio.h>
- #include <fcntl.h>
- #include <sys\stat.h>
-
- main(argc, argv)
- int argc;
- char *argv[];
-
- {
-
- int fp;
-
- if (argc < 2) {
- printf("USAGE: testopen pathname\n");
- exit(1);
- }
-
- /* test _open */
-
- if ((fp=_open(argv[1], O_RDWR|O_CREAT, S_IREAD|S_IWRITE)) != -1) {
- printf("_open: OK. fp = %d\n", fp);
- _close(fp);
- unlink(argv[1]);
- }
- else
- perror("_open");
-
-
- /* test open */
-
- if ((fp=open(argv[1], O_RDWR|O_CREAT, S_IREAD|S_IWRITE)) != -1) {
- printf("open: OK. fp = %d\n", fp);
- close(fp);
- unlink(argv[1]);
- }
- else
- perror("open");
-
-
- /* test _open again*/
-
- if ((fp=_open(argv[1], O_RDWR|O_CREAT, S_IREAD|S_IWRITE)) != -1) {
- printf("_open: still OK. fp = %d\n", fp);
- _close(fp);
- unlink(argv[1]);
- }
- else
- perror("2nd _open");
-
-
- /* test open again */
-
- if ((fp=open(argv[1], O_RDWR|O_CREAT, S_IREAD|S_IWRITE)) != -1) {
- printf("open: still OK. fp = %d\n", fp);
- close(fp);
- unlink(argv[1]);
- }
- else
- perror("2nd open");
-
- }