Mercurial > hg > octave-lojdl > gnulib-hg
annotate lib/fileblocks.c @ 933:6c3fbfcdb059
[HAVE_UNISTD_H]: Include unistd.h.
John Gatewood Ham reported that this is necessary for DJGPP/Win95.
author | Jim Meyering <jim@meyering.net> |
---|---|
date | Tue, 03 Jun 1997 20:01:47 +0000 |
parents | b4ef1c1a0171 |
children | b2ed35578119 |
rev | line source |
---|---|
5 | 1 /* Convert file size to number of blocks on System V-like machines. |
933
6c3fbfcdb059
[HAVE_UNISTD_H]: Include unistd.h.
Jim Meyering <jim@meyering.net>
parents:
650
diff
changeset
|
2 Copyright (C) 1990, 1997 Free Software Foundation, Inc. |
5 | 3 |
4 This program is free software; you can redistribute it and/or modify | |
5 it under the terms of the GNU General Public License as published by | |
6 the Free Software Foundation; either version 2, or (at your option) | |
7 any later version. | |
8 | |
9 This program is distributed in the hope that it will be useful, | |
10 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 GNU General Public License for more details. | |
13 | |
14 You should have received a copy of the GNU General Public License | |
650
b4ef1c1a0171
update FSF address in copyright
Jim Meyering <jim@meyering.net>
parents:
599
diff
changeset
|
15 along with this program; if not, write to the Free Software Foundation, |
b4ef1c1a0171
update FSF address in copyright
Jim Meyering <jim@meyering.net>
parents:
599
diff
changeset
|
16 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
5 | 17 |
18 /* Written by Brian L. Matthews, blm@6sceng.UUCP. */ | |
19 | |
163
4aeea06507af
[!NINDIR]: Define BSIZE only if it's not already defined.
Jim Meyering <jim@meyering.net>
parents:
5
diff
changeset
|
20 #ifdef HAVE_CONFIG_H |
599 | 21 # include <config.h> |
163
4aeea06507af
[!NINDIR]: Define BSIZE only if it's not already defined.
Jim Meyering <jim@meyering.net>
parents:
5
diff
changeset
|
22 #endif |
4aeea06507af
[!NINDIR]: Define BSIZE only if it's not already defined.
Jim Meyering <jim@meyering.net>
parents:
5
diff
changeset
|
23 |
498
89a4657bb64a
Use _POSIX_VERSION, not _POSIX_SOURCE.
Jim Meyering <jim@meyering.net>
parents:
316
diff
changeset
|
24 #if !defined (HAVE_ST_BLOCKS) && !defined(_POSIX_VERSION) |
599 | 25 # include <sys/types.h> |
26 # include <sys/param.h> | |
5 | 27 |
933
6c3fbfcdb059
[HAVE_UNISTD_H]: Include unistd.h.
Jim Meyering <jim@meyering.net>
parents:
650
diff
changeset
|
28 # if HAVE_UNISTD_H |
6c3fbfcdb059
[HAVE_UNISTD_H]: Include unistd.h.
Jim Meyering <jim@meyering.net>
parents:
650
diff
changeset
|
29 # include <unistd.h> |
6c3fbfcdb059
[HAVE_UNISTD_H]: Include unistd.h.
Jim Meyering <jim@meyering.net>
parents:
650
diff
changeset
|
30 # endif |
6c3fbfcdb059
[HAVE_UNISTD_H]: Include unistd.h.
Jim Meyering <jim@meyering.net>
parents:
650
diff
changeset
|
31 |
599 | 32 # ifndef NINDIR |
5 | 33 /* Some SysV's, like Irix, seem to lack these. Hope they're correct. */ |
34 /* Size of a indirect block, in bytes. */ | |
599 | 35 # ifndef BSIZE |
36 # define BSIZE 1024 | |
37 # endif | |
5 | 38 |
39 /* Number of inode pointers per indirect block. */ | |
599 | 40 # define NINDIR (BSIZE/sizeof(daddr_t)) |
41 # endif /* !NINDIR */ | |
5 | 42 |
43 /* Number of direct block addresses in an inode. */ | |
599 | 44 # define NDIR 10 |
5 | 45 |
46 /* Return the number of 512-byte blocks in a file of SIZE bytes. */ | |
47 | |
48 long | |
49 st_blocks (size) | |
50 long size; | |
51 { | |
52 long datablks = (size + 512 - 1) / 512; | |
53 long indrblks = 0; | |
54 | |
55 if (datablks > NDIR) | |
56 { | |
57 indrblks = (datablks - NDIR - 1) / NINDIR + 1; | |
58 | |
59 if (datablks > NDIR + NINDIR) | |
60 { | |
61 indrblks += (datablks - NDIR - NINDIR - 1) / (NINDIR * NINDIR) + 1; | |
62 | |
63 if (datablks > NDIR + NINDIR + NINDIR * NINDIR) | |
64 indrblks++; | |
65 } | |
66 } | |
67 | |
68 return datablks + indrblks; | |
69 } | |
598
e504ab9c8abf
[HAVE_ST_BLOCKS || _POSIX_VERSION]: Add extern dcl
Jim Meyering <jim@meyering.net>
parents:
498
diff
changeset
|
70 #else |
e504ab9c8abf
[HAVE_ST_BLOCKS || _POSIX_VERSION]: Add extern dcl
Jim Meyering <jim@meyering.net>
parents:
498
diff
changeset
|
71 /* This declaration is solely to ensure that after preprocessing |
e504ab9c8abf
[HAVE_ST_BLOCKS || _POSIX_VERSION]: Add extern dcl
Jim Meyering <jim@meyering.net>
parents:
498
diff
changeset
|
72 this file is never empty. */ |
e504ab9c8abf
[HAVE_ST_BLOCKS || _POSIX_VERSION]: Add extern dcl
Jim Meyering <jim@meyering.net>
parents:
498
diff
changeset
|
73 extern int textutils_fileblocks_unused; |
5 | 74 #endif |