From patchwork Thu Jan 19 14:04:42 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 136841 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id F2FEB1007D3 for ; Fri, 20 Jan 2012 01:05:20 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1327586722; h=Comment: DomainKey-Signature:Received:Received:Received:Received: Message-ID:Date:From:User-Agent:MIME-Version:To:Subject: Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=RpE6B/4 aqOGtpmK/N0wC6SFctVI=; b=gcQCxS41viFfrBbu/KRPBfo32GrlPsTV4q6p1oV 4+2s9RFu9wBvNIClEykE3uS9TWeUd+h/QaEtGt1taUSGJlPZq+N1h5ge46jCOloD OSJaUpAX6cZkSNprsVIlOhr8nD0+jdn8x6+7BSKZQHM9ZdXGb9uyPQuLKGqT79aD p3X4= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Message-ID:Date:From:User-Agent:MIME-Version:To:Subject:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=GyKM65B/yc7T2Bw9hi8gTd2xwAeXMg19cy1LIm/1fYyop5pRH1wNYAS5pA4VQ+ hNfRPz+TPyHcsLHsbd0hs9cnLQgov/z0+9ea36UUz8n2IsVIR5WidBi9vI8rlT0n hSkzERnnLiK+eyUD1dx5Z3Y8vDU/WrqfAnckchvubGezg=; Received: (qmail 13957 invoked by alias); 19 Jan 2012 14:05:08 -0000 Received: (qmail 13938 invoked by uid 22791); 19 Jan 2012 14:05:05 -0000 X-SWARE-Spam-Status: No, hits=2.4 required=5.0 tests=AWL, BAYES_00, KAM_MX3, RCVD_IN_DNSWL_NONE, TW_BG, TW_PW, TW_TP, TW_WU, URIBL_BLACK X-Spam-Check-By: sourceware.org Received: from mx01.qsc.de (HELO mx01.qsc.de) (213.148.129.14) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 19 Jan 2012 14:04:45 +0000 Received: from [192.168.178.22] (port-92-204-44-29.dynamic.qsc.de [92.204.44.29]) by mx01.qsc.de (Postfix) with ESMTP id 241E43CAA4; Thu, 19 Jan 2012 15:04:42 +0100 (CET) Message-ID: <4F1822FA.2060803@net-b.de> Date: Thu, 19 Jan 2012 15:04:42 +0100 From: Tobias Burnus User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:9.0) Gecko/20111220 Thunderbird/9.0 MIME-Version: 1.0 To: gcc patches , gfortran Subject: [Patch, Fortran] PR 51899 - Fix building libgfortran's chmod.c with MinGW Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org This patch fixes three issues with building libgfortran for MinGW/MinGW64: a) mode_t is unsigned short while scanf's %o expects an unsigned int variable. b) umask is not available c) Only read and write is available but not group/other read/write/execute, SUID/SGID or the sticky bit. Thanks to Kai for some advice - he also stated that the patch looks okay. Bootstrapped on x86-64-linux, but not (yet) tested on MinGW/MinGW64 OK for the trunk? Tobias 2012-01-19 Tobias Burnus PR libgfortran/51899 * configure.ac: Check whether umask is available. * intrinsics/chmod.c (chmod_func): Make compile with MinGW. * configure: Regenerate. * config.h.in: Regenerate. diff --git a/libgfortran/config.h.in b/libgfortran/config.h.in index 3bba6e6..3739309 100644 --- a/libgfortran/config.h.in +++ b/libgfortran/config.h.in @@ -783,6 +783,9 @@ /* Define to 1 if the system has the type `uintptr_t'. */ #undef HAVE_UINTPTR_T +/* Define to 1 if you have the `umask' function. */ +#undef HAVE_UMASK + /* Define to 1 if you have the header file. */ #undef HAVE_UNISTD_H diff --git a/libgfortran/configure b/libgfortran/configure index 3cf9ac8..0498238 100755 --- a/libgfortran/configure +++ b/libgfortran/configure @@ -2591,6 +2591,7 @@ as_fn_append ac_func_list " getpid" as_fn_append ac_func_list " getppid" as_fn_append ac_func_list " getuid" as_fn_append ac_func_list " geteuid" +as_fn_append ac_func_list " umask" # Check that the precious variables saved in the cache have kept the same # value. ac_cache_corrupted=false @@ -12317,7 +12318,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 12320 "configure" +#line 12321 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -12423,7 +12424,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 12426 "configure" +#line 12427 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -16532,6 +16533,8 @@ done + + # Check for C99 (and other IEEE) math functions { $as_echo "$as_me:${as_lineno-$LINENO}: checking for acosf in -lm" >&5 $as_echo_n "checking for acosf in -lm... " >&6; } diff --git a/libgfortran/configure.ac b/libgfortran/configure.ac index e8bbda5..af987bd 100644 --- a/libgfortran/configure.ac +++ b/libgfortran/configure.ac @@ -266,7 +266,7 @@ ftruncate chsize chdir getlogin gethostname kill link symlink sleep ttyname \ alarm access fork execl wait setmode execve pipe dup2 close \ strcasestr getrlimit gettimeofday stat fstat lstat getpwuid vsnprintf dup \ getcwd localtime_r gmtime_r strerror_r getpwuid_r ttyname_r clock_gettime \ -readlink getgid getpid getppid getuid geteuid) +readlink getgid getpid getppid getuid geteuid umask) # Check for C99 (and other IEEE) math functions AC_CHECK_LIB([m],[acosf],[AC_DEFINE([HAVE_ACOSF],[1],[libm includes acosf])]) diff --git a/libgfortran/intrinsics/chmod.c b/libgfortran/intrinsics/chmod.c index 6c685f4..01db8be 100644 --- a/libgfortran/intrinsics/chmod.c +++ b/libgfortran/intrinsics/chmod.c @@ -37,6 +37,9 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see Sets the file permission "chmod" using a mode string. + For MinGW, only _S_IWRITE and _S_IREAD are supported. To set those, + only the user attributes are used. + The mode string allows for the same arguments as POSIX's chmod utility. a) string containing an octal number. b) Comma separated list of clauses of the form: @@ -89,8 +92,15 @@ chmod_func (char *name, char *mode, gfc_charlen_type name_len, if (mode[0] >= '0' && mode[0] <= '9') { +#ifdef __MINGW32__ + unsigned mode; + if (sscanf (mode, "%o", &mode) != 1) + return 1; + file_mode = (mode_t) mode; +#else if (sscanf (mode, "%o", &file_mode) != 1) return 1; +#endif return chmod (file, file_mode); } @@ -101,10 +111,14 @@ chmod_func (char *name, char *mode, gfc_charlen_type name_len, file_mode = stat_buf.st_mode & ~S_IFMT; is_dir = stat_buf.st_mode & S_IFDIR; +#ifdef HAVE_UMASK /* Obtain the umask without distroying the setting. */ mode_mask = 0; mode_mask = umask (mode_mask); (void) umask (mode_mask); +#else + honor_umask = false; +#endif for (i = 0; i < mode_len; i++) { @@ -113,7 +127,9 @@ chmod_func (char *name, char *mode, gfc_charlen_type name_len, ugo[0] = false; ugo[1] = false; ugo[2] = false; +#ifdef HAVE_UMASK honor_umask = true; +#endif } continue_clause = false; rwxXstugo[0] = false; @@ -140,7 +156,9 @@ chmod_func (char *name, char *mode, gfc_charlen_type name_len, ugo[1] = true; ugo[2] = true; part = 1; +#ifdef HAVE_UMASK honor_umask = false; +#endif break; case 'u': if (part == 2) @@ -153,7 +171,9 @@ chmod_func (char *name, char *mode, gfc_charlen_type name_len, return 1; ugo[0] = true; part = 1; +#ifdef HAVE_UMASK honor_umask = false; +#endif break; case 'g': if (part == 2) @@ -166,7 +186,9 @@ chmod_func (char *name, char *mode, gfc_charlen_type name_len, return 1; ugo[1] = true; part = 1; +#ifdef HAVE_UMASK honor_umask = false; +#endif break; case 'o': if (part == 2) @@ -179,7 +201,9 @@ chmod_func (char *name, char *mode, gfc_charlen_type name_len, return 1; ugo[2] = true; part = 1; +#ifdef HAVE_UMASK honor_umask = false; +#endif break; /* Mode setting: =+-. */ @@ -285,6 +309,18 @@ clause_done: new_mode = 0; +#ifdef __MINGW32__ + + /* Read. */ + if (rwxXstugo[0] && (ugo[0] || honor_umask)) + new_mode |= _S_IREAD; + + /* Write. */ + if (rwxXstugo[1] && (ugo[0] || honor_umask)) + new_mode |= _S_IWRITE; + +#else + /* Read. */ if (rwxXstugo[0]) { @@ -400,12 +436,20 @@ clause_done: new_mode |= S_IXGRP; } } +#endif /* __MINGW32__ */ +#ifdef HAVE_UMASK if (honor_umask) new_mode &= ~mode_mask; +#endif if (set_mode == 1) { +#ifdef __MINGW32__ + if (ugo[0] || honor_umask) + file_mode = (file_mode & ~(_S_IWRITE | _S_IREAD)) + | (new_mode & (_S_IWRITE | _S_IREAD)); +#else /* Set '='. */ if ((ugo[0] || honor_umask) && !rwxXstugo[6]) file_mode = (file_mode & ~(S_ISUID | S_IRUSR | S_IWUSR | S_IXUSR)) @@ -420,21 +464,26 @@ clause_done: file_mode |= S_ISVTX; else if (!is_dir) file_mode &= ~S_ISVTX; +#endif } else if (set_mode == 2) { /* Clear '-'. */ file_mode &= ~new_mode; +#ifndef __MINGW32__ if (rwxXstugo[5] || !is_dir) file_mode &= ~S_ISVTX; +#endif } else if (set_mode == 3) { file_mode |= new_mode; +#ifndef __MINGW32__ if (rwxXstugo[5] && is_dir) file_mode |= S_ISVTX; else if (!is_dir) file_mode &= ~S_ISVTX; +#endif } } @@ -442,7 +491,6 @@ clause_done: } - extern void chmod_i4_sub (char *, char *, GFC_INTEGER_4 *, gfc_charlen_type, gfc_charlen_type); export_proto(chmod_i4_sub);