00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "ad_ufs.h"
00010
00011 void ADIOI_UFS_Open(ADIO_File fd, int *error_code)
00012 {
00013 int perm, old_mask, amode;
00014 #ifndef PRINT_ERR_MSG
00015 static char myname[] = "ADIOI_UFS_OPEN";
00016 #endif
00017
00018 if (fd->perm == ADIO_PERM_NULL) {
00019 old_mask = umask(022);
00020 umask(old_mask);
00021 perm = old_mask ^ 0666;
00022 }
00023 else perm = fd->perm;
00024
00025 amode = 0;
00026 if (fd->access_mode & ADIO_CREATE)
00027 amode = amode | O_CREAT;
00028 if (fd->access_mode & ADIO_RDONLY)
00029 amode = amode | O_RDONLY;
00030 if (fd->access_mode & ADIO_WRONLY)
00031 amode = amode | O_WRONLY;
00032 if (fd->access_mode & ADIO_RDWR)
00033 amode = amode | O_RDWR;
00034 if (fd->access_mode & ADIO_EXCL)
00035 amode = amode | O_EXCL;
00036
00037 fd->fd_sys = open(fd->filename, amode, perm);
00038
00039 if ((fd->fd_sys != -1) && (fd->access_mode & ADIO_APPEND))
00040 fd->fp_ind = fd->fp_sys_posn = lseek(fd->fd_sys, 0, SEEK_END);
00041
00042 #ifdef PRINT_ERR_MSG
00043 *error_code = (fd->fd_sys == -1) ? MPI_ERR_UNKNOWN : MPI_SUCCESS;
00044 #else
00045 if (fd->fd_sys == -1) {
00046 *error_code = MPIR_Err_setmsg(MPI_ERR_IO, MPIR_ADIO_ERROR,
00047 myname, "I/O Error", "%s", strerror(errno));
00048 ADIOI_Error(ADIO_FILE_NULL, *error_code, myname);
00049 }
00050 else *error_code = MPI_SUCCESS;
00051 #endif
00052 }