Skip to content

Commit c679fa8

Browse files
committed
Fix build with link-time optimization
When building with link-time optimization enabled, the compiler errors out due to some arrays being declared with different sizes in different compilation units. All of the problematic declarations are of character arrays of size MAXPATHLEN in xv.h, which is included by all of xv's source files. However, the value of the token MAXPATHLEN varies depending on whether or not the token NEEDSDIR is defined at the time of xv.h's inclusion. If it is defined, MAXPATHLEN will be defined via system headers, typically to a value of 4096. If it is not defined, a default value of 256 is used. The NEEDSDIR mechanism was probably created to speed up compilation by not including files unnecessarily on the very old and slow systems that xv was originally written for, and is almost certainly unnecessary now. Hence, the fix for this issue is to get rid of NEEDSDIR altogether and just include the necessary files unconditionally. Fixes #25.
1 parent be94fb3 commit c679fa8

File tree

12 files changed

+19
-36
lines changed

12 files changed

+19
-36
lines changed

src/xv.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
#define MAIN
88
#define NEEDSTIME
9-
#define NEEDSDIR /* for value of MAXPATHLEN */
109

1110
#include "xv.h"
1211

src/xv.h

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -293,31 +293,26 @@
293293

294294

295295

296-
#ifdef NEEDSDIR
297-
# ifdef VMS
298-
# include <descrip.h>
299-
# include <stat.h>
300-
# include "dirent.h"
296+
#ifdef VMS
297+
# include <descrip.h>
298+
# include <stat.h>
299+
# include "dirent.h"
300+
#else
301+
# ifdef NODIRENT
302+
# include <sys/dir.h>
301303
# else
302-
# ifdef NODIRENT
303-
# include <sys/dir.h>
304-
# else
305-
# include <dirent.h>
306-
# endif
307-
308-
# if defined(SVR4) || defined(SYSV)
309-
# include <fcntl.h>
310-
# endif
311-
312-
# include <sys/param.h>
313-
# include <sys/stat.h>
314-
315-
# if defined(__convex__) && defined (__STDC__)
316-
# define S_IFMT _S_IFMT
317-
# define S_IFDIR _S_IFDIR
318-
# define S_IFCHR _S_IFCHR
319-
# define S_IFBLK _S_IFBLK
320-
# endif
304+
# include <dirent.h>
305+
# endif
306+
# if defined(SVR4) || defined(SYSV)
307+
# include <fcntl.h>
308+
# endif
309+
# include <sys/param.h>
310+
# include <sys/stat.h>
311+
# if defined(__convex__) && defined (__STDC__)
312+
# define S_IFMT _S_IFMT
313+
# define S_IFDIR _S_IFDIR
314+
# define S_IFCHR _S_IFCHR
315+
# define S_IFBLK _S_IFBLK
321316
# endif
322317
#endif
323318

src/xvbrowse.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
#include "copyright.h"
1919

20-
#define NEEDSDIR
2120
#include "xv.h"
2221
#include <unistd.h> /* access() */
2322

src/xvcut.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
*/
4848

4949

50-
#define NEEDSDIR /* for stat() */
5150
#include "copyright.h"
5251
#include "xv.h"
5352

src/xvdir.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#include "copyright.h"
2222

2323
#define NEEDSTIME /* for CheckPoll */
24-
#define NEEDSDIR
2524
#include "xv.h"
2625

2726
#include "bits/d_load"

src/xvfits.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
* provided "as is" without express or implied warranty.
1515
*/
1616

17-
#define NEEDSDIR /* for S_IRUSR|S_IWUSR */
1817
#include "xv.h"
1918

2019
#define NCARDS (36)

src/xvimage.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
*/
3131
/* #define ENABLE_FIXPIX_SMOOTH */ /* GRR 19980607: moved into xv.h */
3232

33-
#define NEEDSDIR /* for S_IRUSR|S_IWUSR */
3433
#include "copyright.h"
3534

3635
#include "xv.h"

src/xvmgcsfx.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@
6060
* 同様に書き込み時にも問題が生じるかもしれない。
6161
*/
6262

63-
#define NEEDSDIR /* for stat() */
6463
#include "xv.h"
6564

6665

src/xvpds.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@
101101
* This software is provided "as is" without any express or implied warranty.
102102
*/
103103

104-
#define NEEDSDIR /* for S_IRUSR|S_IWUSR */
105104
#include "xv.h"
106105

107106
#ifdef HAVE_PDS

src/xvpic2.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@
6161
*/
6262

6363
#define PIC2_IGNORE_UNUSED_FUNCTIONS
64-
#define NEEDSDIR
6564

6665
#include "xv.h"
6766
#include <setjmp.h>

0 commit comments

Comments
 (0)