LCOV - code coverage report
Current view: top level - gutils - gutils.c (source / functions) Hit Total Coverage
Test: FontForge coverage report 2017-08-04 01:21:11+02:00 (commit d35f7e4107a9e1db65cce47c468fcc914cecb8fd) Lines: 11 19 57.9 %
Date: 2017-08-04 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /* Copyright (C) 2000-2012 by George Williams */
       2             : /*
       3             :  * Redistribution and use in source and binary forms, with or without
       4             :  * modification, are permitted provided that the following conditions are met:
       5             : 
       6             :  * Redistributions of source code must retain the above copyright notice, this
       7             :  * list of conditions and the following disclaimer.
       8             : 
       9             :  * Redistributions in binary form must reproduce the above copyright notice,
      10             :  * this list of conditions and the following disclaimer in the documentation
      11             :  * and/or other materials provided with the distribution.
      12             : 
      13             :  * The name of the author may not be used to endorse or promote products
      14             :  * derived from this software without specific prior written permission.
      15             : 
      16             :  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
      17             :  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
      18             :  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
      19             :  * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
      20             :  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
      21             :  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
      22             :  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
      23             :  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
      24             :  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
      25             :  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
      26             :  */
      27             : 
      28             : #include "basics.h"
      29             : #include "gutils.h"
      30             : 
      31             : #include <stdio.h>
      32             : #include <math.h>
      33             : #include <stdlib.h>
      34             : #include <string.h>
      35             : #include <ustring.h>
      36             : #include <utype.h>
      37             : #include <unistd.h>
      38             : #include <locale.h>
      39             : #if !defined(__MINGW32__)
      40             : # include <pwd.h>
      41             : #endif
      42             : #include <stdarg.h>
      43             : #include <time.h>
      44             : #include <gdraw.h>                /* For image defn */
      45             : 
      46             : #ifdef __CygWin
      47             :  #include <sys/types.h>
      48             :  #include <sys/stat.h>
      49             :  #include <unistd.h>
      50             : #endif
      51             : 
      52             : 
      53          15 : const char *GetAuthor(void) {
      54             : #if defined(__MINGW32__)
      55             :     static char author[200] = { '\0' };
      56             :     if ( author[0] == '\0' ){
      57             :         char* name = getenv("USER");
      58             :         if(!name) return NULL;
      59             :         strncpy(author, name, sizeof(author));
      60             :         author[sizeof(author)-1] = '\0';
      61             :     }
      62             :     return author;
      63             : #else
      64             :     struct passwd *pwd;
      65             :     static char author[200] = { '\0' };
      66          15 :     const char *ret = NULL, *pt;
      67             : 
      68          15 :     if ( author[0]!='\0' )
      69           2 : return( author );
      70             : 
      71             : /* Can all be commented out if no pwd routines */
      72          13 :     pwd = getpwuid(getuid());
      73          13 :     if ( pwd!=NULL && pwd->pw_gecos!=NULL && *pwd->pw_gecos!='\0' ) {
      74          13 :         strncpy(author,pwd->pw_gecos,sizeof(author));
      75          13 :         author[sizeof(author)-1] = '\0';
      76          13 :         ret = author;
      77           0 :     } else if ( pwd!=NULL && pwd->pw_name!=NULL && *pwd->pw_name!='\0' ) {
      78           0 :         strncpy(author,pwd->pw_name,sizeof(author));
      79           0 :         author[sizeof(author)-1] = '\0';
      80           0 :         ret = author;
      81           0 :     } else if ( (pt=getenv("USER"))!=NULL ) {
      82           0 :         strncpy(author,pt,sizeof(author));
      83           0 :         author[sizeof(author)-1] = '\0';
      84           0 :         ret = author;
      85             :     }
      86          13 :     endpwent();
      87             : /* End comment */
      88          13 : return( ret );
      89             : #endif
      90             : }
      91             : 

Generated by: LCOV version 1.10