Coverage Report

Created: 2025-12-03 07:28

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/graphicsmagick/magick/unix_port.c
Line
Count
Source
1
/*
2
% Copyright (C) 2007-2016 GraphicsMagick Group
3
%
4
% This program is covered by multiple licenses, which are described in
5
% Copyright.txt. You should have received a copy of Copyright.txt with this
6
% package; otherwise see http://www.graphicsmagick.org/www/Copyright.html.
7
%
8
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9
%                                                                             %
10
%                                                                             %
11
%                                                                             %
12
%                       U   U  N   N  IIIII  X   X                            %
13
%                       U   U  NN  N    I     X X                             %
14
%                       U   U  N N N    I      X                              %
15
%                       U   U  N  NN    I     X X                             %
16
%                        UUU   N   N  IIIII  X   X                            %
17
%                                                                             %
18
%                                                                             %
19
%                       GraphicsMagick UNIX Methods                           %
20
%                                                                             %
21
%                                                                             %
22
%                             Software Design                                 %
23
%                             Bob Friesenhahn                                 %
24
%                                July 2007                                    %
25
%                                                                             %
26
%                                                                             %
27
%                                                                             %
28
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29
%
30
%
31
*/
32

33
/*
34
  Include declarations.
35
*/
36
#include "magick/studio.h"
37
#include "magick/confirm_access.h"
38
#if defined(POSIX)
39
/* some of these may have already been included by studio.h */
40
#include <stdio.h>
41
#include <string.h>
42
#include <sys/types.h>
43
#include <unistd.h>
44
#include <errno.h>
45
#include <sys/wait.h>
46
#include <sys/types.h>
47
#include <utime.h>
48
#include "magick/utility.h"
49

50
/*
51
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
52
%                                                                             %
53
%                                                                             %
54
%                                                                             %
55
%   M a g i c k G e t M M U P a g e S i z e                                   %
56
%                                                                             %
57
%                                                                             %
58
%                                                                             %
59
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
60
%
61
%  MagickGetMMUPageSize() returns the VM pagesize used by the MMU. The VM
62
%  pagesize is the number of bytes retrieved due to one page fault.
63
%
64
%  The format of the MagickGetMMUPageSize method is:
65
%
66
%      long MagickGetMMUPageSize()
67
%
68
*/
69
MagickExport long MagickGetMMUPageSize(void)
70
389
{
71
389
  static long
72
389
    pagesize = 0;
73
74
389
  if (pagesize <= 0)
75
252
    {
76
252
#if defined(HAVE_SYSCONF) && defined(_SC_PAGE_SIZE)
77
252
      pagesize=sysconf(_SC_PAGE_SIZE);
78
252
#endif /* defined(HAVE_SYSCONF) && defined(_SC_PAGE_SIZE) */
79
252
#if defined(HAVE_GETPAGESIZE)
80
252
      if (pagesize <= 0)
81
0
        pagesize=getpagesize();
82
252
#endif /* defined(HAVE_GETPAGESIZE) */
83
252
      if (pagesize <= 0)
84
0
        pagesize=16384;
85
252
    }
86
87
389
  return pagesize;
88
389
}
89

90
/*
91
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
92
%                                                                             %
93
%                                                                             %
94
%                                                                             %
95
%   M a g i c k G e t F i l e A t t r i b u t e s                             %
96
%                                                                             %
97
%                                                                             %
98
%                                                                             %
99
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
100
%
101
%  MagickGetFileAttributes() returns the file attributes for a specified
102
%  file in a structure of type MagickStatStruct_t.
103
%
104
%  The format of the MagickGetFileAttributes method is:
105
%
106
%      int MagickGetFileAttributes(const char *filename,
107
%                                  MagickStatStruct_t *statbuf)
108
%
109
%  A description of each parameter follows:
110
%
111
%    o filename:  Path to the file
112
%
113
%    o statbuf: A structure of type MagickStatStruct_t to populate.
114
%
115
%
116
*/
117
MagickExport int MagickGetFileAttributes(const char *filename,
118
                                         MagickStatStruct_t *statbuf)
119
0
{
120
0
  if (MagickStat(filename, statbuf) != 0)
121
0
    return -1;
122
123
0
  return 0;
124
0
}
125

126
/*
127
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
128
%                                                                             %
129
%                                                                             %
130
%                                                                             %
131
%   M a g i c k S e t F i l e A t t r i b u t e s                             %
132
%                                                                             %
133
%                                                                             %
134
%                                                                             %
135
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
136
%
137
%  MagickSetFileAttributes() sets the access and modification time file
138
%  attributes based on values provided via in a structure of type
139
%  MagickStatStruct_t.
140
%
141
%  The format of the MagickGetFileAttributes method is:
142
%
143
%      int MagickSetFileAttributes(const char *filename,
144
%                                  const MagickStatStruct_t *statbuf)
145
%
146
%  A description of each parameter follows:
147
%
148
%    o filename:  Path to the file
149
%
150
%    o statbuf: A structure of type MagickStatStruct_t to populate.
151
%
152
%
153
*/
154
MagickExport int MagickSetFileAttributes(const char *filename,
155
                                         const MagickStatStruct_t *statbuf)
156
0
{
157
0
  struct utimbuf
158
0
    utbuf;
159
160
0
  utbuf.actime = statbuf->st_atime;
161
0
  utbuf.modtime = statbuf->st_mtime;
162
163
0
  if (utime(filename, &utbuf) != 0)
164
0
    return -1;
165
166
0
  return 0;
167
0
}
168
169
#endif /* defined(POSIX) */