<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic does file truncate affect current file offset in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/does-file-truncate-affect-current-file-offset/m-p/4646763#M676806</link>
    <description>i can truncate a file to increase or decrease the file EOF.&lt;BR /&gt;does this change the current file offset?&lt;BR /&gt;if it dont then do i have to place the file offset to correct&lt;BR /&gt;place in my program ?&lt;BR /&gt;&lt;BR /&gt;Scotty</description>
    <pubDate>Sat, 12 Jun 2010 11:46:59 GMT</pubDate>
    <dc:creator>Scotty HD</dc:creator>
    <dc:date>2010-06-12T11:46:59Z</dc:date>
    <item>
      <title>does file truncate affect current file offset</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/does-file-truncate-affect-current-file-offset/m-p/4646763#M676806</link>
      <description>i can truncate a file to increase or decrease the file EOF.&lt;BR /&gt;does this change the current file offset?&lt;BR /&gt;if it dont then do i have to place the file offset to correct&lt;BR /&gt;place in my program ?&lt;BR /&gt;&lt;BR /&gt;Scotty</description>
      <pubDate>Sat, 12 Jun 2010 11:46:59 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/does-file-truncate-affect-current-file-offset/m-p/4646763#M676806</guid>
      <dc:creator>Scotty HD</dc:creator>
      <dc:date>2010-06-12T11:46:59Z</dc:date>
    </item>
    <item>
      <title>Re: does file truncate affect current file offset</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/does-file-truncate-affect-current-file-offset/m-p/4646764#M676807</link>
      <description>You really should have specified which programming/scripting language you're talnking about...&lt;BR /&gt;&lt;BR /&gt;But according to the POSIX standard, the truncate()/ftruncate() system call will not modify the file offset.&lt;BR /&gt;&lt;BR /&gt;It is not mandatory to change the file offset after shortening a file with a truncate operation; but if you don't, you may be creating a sparse file (intentionally or otherwise).&lt;BR /&gt;&lt;BR /&gt;Please see:&lt;BR /&gt;&lt;A href="http://en.wikipedia.org/wiki/Sparse_file" target="_blank"&gt;http://en.wikipedia.org/wiki/Sparse_file&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;The Wikipedia page talks about sparse files in Linux, but HP-UX and most other modern Unix-like filesystems will behave the same way.&lt;BR /&gt;&lt;BR /&gt;MK</description>
      <pubDate>Sat, 12 Jun 2010 12:13:33 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/does-file-truncate-affect-current-file-offset/m-p/4646764#M676807</guid>
      <dc:creator>Matti_Kurkela</dc:creator>
      <dc:date>2010-06-12T12:13:33Z</dc:date>
    </item>
    <item>
      <title>Re: does file truncate affect current file offset</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/does-file-truncate-affect-current-file-offset/m-p/4646765#M676808</link>
      <description>Matti Kurkela&amp;gt;&amp;gt;&lt;BR /&gt;thanks for reply&lt;BR /&gt;&lt;BR /&gt;i take example to understand better.&lt;BR /&gt;My file has eof at 500 blocks.current offset is at 400 blocks.&lt;BR /&gt;now i truncate file to 300 blocks.&lt;BR /&gt;&lt;BR /&gt;so according to POSIX standard,&lt;BR /&gt;what is current file offset?&lt;BR /&gt;next read/write on file will be from what position in file?&lt;BR /&gt;&lt;BR /&gt;Scotty</description>
      <pubDate>Sat, 12 Jun 2010 12:23:38 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/does-file-truncate-affect-current-file-offset/m-p/4646765#M676808</guid>
      <dc:creator>Scotty HD</dc:creator>
      <dc:date>2010-06-12T12:23:38Z</dc:date>
    </item>
    <item>
      <title>Re: does file truncate affect current file offset</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/does-file-truncate-affect-current-file-offset/m-p/4646766#M676809</link>
      <description>&amp;gt;so according to POSIX standard, what is current file offset?&lt;BR /&gt;&lt;BR /&gt;Unchanged at 400 * blocksize.&lt;BR /&gt;&lt;BR /&gt;&amp;gt;next read/write on file will be from what position in file?&lt;BR /&gt;&lt;BR /&gt;A read should get an error (the extra data shall no longer be available to reads on the file) and a write may leave a hole.</description>
      <pubDate>Sat, 12 Jun 2010 12:38:27 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/does-file-truncate-affect-current-file-offset/m-p/4646766#M676809</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2010-06-12T12:38:27Z</dc:date>
    </item>
    <item>
      <title>Re: does file truncate affect current file offset</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/does-file-truncate-affect-current-file-offset/m-p/4646767#M676810</link>
      <description>As Dennis said, the offset will be unchanged, so a read operation without changing the offset will fail.&lt;BR /&gt;&lt;BR /&gt;But if you write 1 block, the write will happen to block 400, and after the write, the offset will be at block 401. The file size will jump from 300 to 401 blocks.&lt;BR /&gt;&lt;BR /&gt;Your file will now consist of 300 blocks of existing data + 100 blocks of zero bytes + 1 block of new data. The "ls -l" will report a file size of (block size * 401 blocks). If another program would read the file from the beginning to the end, the program would get 401 blocks of data from the file.&lt;BR /&gt;&lt;BR /&gt;But if the filesystem supports sparse files, then instead of storing those 100 blocks of zeroes, the filesystem makes a brief note to the metadata of the file: "100 blocks of zeroes at blocks 300-399". Because those blocks don't really exist on the disk, the "du" command will report the file occupies only 301 blocks on the disk.&lt;BR /&gt;&lt;BR /&gt;If you later change the file offset and write something to the 100-block "hole", the filesystem will transparently allocate real disk blocks to cover parts of the hole as necessary. Once the hole is completely filled, the sizes reported by "du" and "ls -l" will again be in agreement.&lt;BR /&gt;&lt;BR /&gt;If the underlying filesystem did not support sparse files, the POSIX semantics would require the OS to automatically write blocks 300-399 to the disk as real blocks of zero bytes.&lt;BR /&gt;&lt;BR /&gt;MK</description>
      <pubDate>Sat, 12 Jun 2010 15:12:36 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/does-file-truncate-affect-current-file-offset/m-p/4646767#M676810</guid>
      <dc:creator>Matti_Kurkela</dc:creator>
      <dc:date>2010-06-12T15:12:36Z</dc:date>
    </item>
    <item>
      <title>Re: does file truncate affect current file offset</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/does-file-truncate-affect-current-file-offset/m-p/4646768#M676811</link>
      <description>Dennis Handly&amp;gt;&amp;gt;, Matti Kurkela&amp;gt;&amp;gt;&lt;BR /&gt;Thanks for reply.&lt;BR /&gt;&lt;BR /&gt;i remember writing program before where i saw the file offset getting&lt;BR /&gt;set to new EOF after i truncate it. may be i did some program error.&lt;BR /&gt;i need to check where i kept that program.&lt;BR /&gt;&lt;BR /&gt;if somebody give me a program it is helpful. i want program to truncate&lt;BR /&gt;a file to increase and decrease file length. in both case i want to know&lt;BR /&gt;file offset after trucate and also do a read/write after truncate and&lt;BR /&gt;check where the data gets read/write to file.&lt;BR /&gt;&lt;BR /&gt;Scotty</description>
      <pubDate>Sat, 12 Jun 2010 15:41:30 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/does-file-truncate-affect-current-file-offset/m-p/4646768#M676811</guid>
      <dc:creator>Scotty HD</dc:creator>
      <dc:date>2010-06-12T15:41:30Z</dc:date>
    </item>
    <item>
      <title>Re: does file truncate affect current file offset</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/does-file-truncate-affect-current-file-offset/m-p/4646769#M676812</link>
      <description>I (and apparently also Dennis) talked about the behaviors and semantics of POSIX-compliant systems. When you program in C on HP-UX or some other Unix-like platform, that's what you usually get.&lt;BR /&gt;&lt;BR /&gt;But if you program in Java, you will have the Java Virtual Machine between your code and the operating system. JVM will hide the semantics of the OS (POSIX, MS-Windows or whatever) and provide another set of semantics that is (supposed to be) uniform across all the OS/hardware platforms Java can run on. &lt;BR /&gt;&lt;BR /&gt;If Java API specifies that a truncate operation must change the file offset to the new EOF, then the JVM could automatically execute "lseek (fd, 0, SEEK_END);" system call (or something equivalent) after each file truncation operation when it runs on a POSIX-compliant platform.&lt;BR /&gt;&lt;BR /&gt;Even a C programmer can see different semantics, if he/she uses the API of some project-specific library instead of the POSIX API. In that case, the semantics should be described in the documentation of that library.&lt;BR /&gt;&lt;BR /&gt;So, unless you tell us at least the name of the programming language you're using, the only answer that can be given without making any guesses about your programming environment is "Please read the documentation of the programming API you're using".&lt;BR /&gt;&lt;BR /&gt;If you want an example program, the choice of the programming language is even more important: if the language of some provided example is not important to you, the time spent in writing it is simply wasted.&lt;BR /&gt;&lt;BR /&gt;MK</description>
      <pubDate>Sat, 12 Jun 2010 19:02:53 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/does-file-truncate-affect-current-file-offset/m-p/4646769#M676812</guid>
      <dc:creator>Matti_Kurkela</dc:creator>
      <dc:date>2010-06-12T19:02:53Z</dc:date>
    </item>
    <item>
      <title>Re: does file truncate affect current file offset</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/does-file-truncate-affect-current-file-offset/m-p/4646770#M676813</link>
      <description>&lt;!--!*#--&gt;Hi Scotty:&lt;BR /&gt;&lt;BR /&gt;Here's a simple Perl script that opens and writes a 500-character file; seek();s backwards 100-characters; and then truncate()s the file to an overall length of 300 before writing one character more.  Since no seek() was performed after the truncate(), the position in the file was unchanged.&lt;BR /&gt;&lt;BR /&gt;As Dennis noted, the read() failed after the truncate() and the subsequent write() created a sparse file (one with "holes").  You can see this as follows:&lt;BR /&gt;&lt;BR /&gt;# cat ./mytruncate&lt;BR /&gt;#!/usr/bin/perl&lt;BR /&gt;use strict;&lt;BR /&gt;use warnings;&lt;BR /&gt;use Fcntl;&lt;BR /&gt;my $fh;&lt;BR /&gt;my $file = '/tmp/myfile';&lt;BR /&gt;&lt;BR /&gt;sub tattle {&lt;BR /&gt;    my @msg = @_;&lt;BR /&gt;    print "offset=", tell($fh), " @msg\n";&lt;BR /&gt;}&lt;BR /&gt;sysopen( $fh, $file, O_RDWR | O_CREAT ) or die "Can't open '$file': $!\n";&lt;BR /&gt;print $fh 'x' for ( 0 .. 499 );    #...file file with 'x' characters...&lt;BR /&gt;tattle("after open and write");&lt;BR /&gt;seek( $fh, -100, 2 );              #...back off from eof...&lt;BR /&gt;tattle("after seek()");&lt;BR /&gt;truncate( $fh, 300 );              #...truncate to offset...&lt;BR /&gt;tattle("after truncate()");&lt;BR /&gt;&lt;BR /&gt;if (&amp;lt;$fh&amp;gt;) {&lt;BR /&gt;    tattle("after successful read");&lt;BR /&gt;}&lt;BR /&gt;else {&lt;BR /&gt;    tattle("after an unsuccessful read");&lt;BR /&gt;}&lt;BR /&gt;print $fh '!';                     #...mark with a exclamination point...&lt;BR /&gt;tattle("after a write");&lt;BR /&gt;1;&lt;BR /&gt;&lt;BR /&gt;# ./mytruncate&lt;BR /&gt;offset=500 after open and write&lt;BR /&gt;offset=400 after seek()&lt;BR /&gt;offset=400 after truncate()&lt;BR /&gt;offset=400 after an unsuccessful read&lt;BR /&gt;offset=401 after a write&lt;BR /&gt;&lt;BR /&gt;# xd -ta /tmp/myfile&lt;BR /&gt;0000000    x   x   x   x   x   x   x   x   x   x   x   x   x   x   x   x&lt;BR /&gt;*&lt;BR /&gt;0000120    x   x   x   x   x   x   x   x   x   x   x   x nul nul nul nul&lt;BR /&gt;0000130  nul nul nul nul nul nul nul nul nul nul nul nul nul nul nul nul&lt;BR /&gt;*&lt;BR /&gt;0000190    !&lt;BR /&gt;0000191&lt;BR /&gt;&lt;BR /&gt;As you can see, in the file dump, 0x190 is decimal 400 (zero-relative) and 0x12b is decimal 299 or offset 300, zero-relative.  The 'nul' characters are the "holes".&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Sat, 12 Jun 2010 20:15:11 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/does-file-truncate-affect-current-file-offset/m-p/4646770#M676813</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2010-06-12T20:15:11Z</dc:date>
    </item>
    <item>
      <title>Re: does file truncate affect current file offset</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/does-file-truncate-affect-current-file-offset/m-p/4646771#M676814</link>
      <description>Matti Kurkela&amp;gt;&amp;gt;&lt;BR /&gt;sorry i missed your question posted earlier about programming language.&lt;BR /&gt;i was referring to C program on HP-UX.&lt;BR /&gt;the JVM stuff you told was intresting.&lt;BR /&gt;&lt;BR /&gt;James R. Ferguson&amp;gt;&amp;gt;&lt;BR /&gt;thanks so much for program. i will run it on HP-UX system and check.&lt;BR /&gt;you have given perl script. c program would also behave similarly, correct ?&lt;BR /&gt;&lt;BR /&gt;Scotty</description>
      <pubDate>Sun, 13 Jun 2010 05:03:22 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/does-file-truncate-affect-current-file-offset/m-p/4646771#M676814</guid>
      <dc:creator>Scotty HD</dc:creator>
      <dc:date>2010-06-13T05:03:22Z</dc:date>
    </item>
    <item>
      <title>Re: does file truncate affect current file offset</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/does-file-truncate-affect-current-file-offset/m-p/4646772#M676815</link>
      <description>&amp;gt;C program would also behave similarly?&lt;BR /&gt;&lt;BR /&gt;Yes.  It is the system calls that matter.  You can download and use tusc to check them.</description>
      <pubDate>Sun, 13 Jun 2010 06:49:49 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/does-file-truncate-affect-current-file-offset/m-p/4646772#M676815</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2010-06-13T06:49:49Z</dc:date>
    </item>
    <item>
      <title>Re: does file truncate affect current file offset</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/does-file-truncate-affect-current-file-offset/m-p/4646773#M676816</link>
      <description>&amp;gt;&amp;gt; Dennis Handly&lt;BR /&gt;# You can download and use tusc to check them.&lt;BR /&gt;can u give me link.&lt;BR /&gt;&lt;BR /&gt;if anybody have c program for truncate, pass it to me&lt;BR /&gt;&lt;BR /&gt;Scotty</description>
      <pubDate>Sun, 13 Jun 2010 09:01:19 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/does-file-truncate-affect-current-file-offset/m-p/4646773#M676816</guid>
      <dc:creator>Scotty HD</dc:creator>
      <dc:date>2010-06-13T09:01:19Z</dc:date>
    </item>
    <item>
      <title>Re: does file truncate affect current file offset</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/does-file-truncate-affect-current-file-offset/m-p/4646774#M676817</link>
      <description>Hi (again) Scotty:&lt;BR /&gt;&lt;BR /&gt;&amp;gt; you have given perl script. c program would also behave similarly, correct ?&lt;BR /&gt;&lt;BR /&gt;Yes.  Perl's guts are written in C and hence use standard system calls.  You can see this in the 'lseek(2)' and 'truncate(2)' calls.  Look at the HP-UX manpages.  &lt;BR /&gt;&lt;BR /&gt;Some of the standard C library functions are re-implemented in Perl's internals but the overall goal is the same.  Perl's 'tell(3S)' is roughly equivalent to the C function 'ftell()'.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Sun, 13 Jun 2010 13:02:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/does-file-truncate-affect-current-file-offset/m-p/4646774#M676817</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2010-06-13T13:02:50Z</dc:date>
    </item>
    <item>
      <title>Re: does file truncate affect current file offset</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/does-file-truncate-affect-current-file-offset/m-p/4646775#M676818</link>
      <description>Hi (again) Scotty:&lt;BR /&gt;&lt;BR /&gt;You can download a 'tusc' binary from the PH-UX Porting Centre.  Installation is done with 'swinstall' into the '/usr/local/bin' directory:&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://hpux.connect.org.uk/hppd/hpux/Sysadmin/tusc-8.0/" target="_blank"&gt;http://hpux.connect.org.uk/hppd/hpux/Sysadmin/tusc-8.0/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Sun, 13 Jun 2010 16:40:47 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/does-file-truncate-affect-current-file-offset/m-p/4646775#M676818</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2010-06-13T16:40:47Z</dc:date>
    </item>
    <item>
      <title>Re: does file truncate affect current file offset</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/does-file-truncate-affect-current-file-offset/m-p/4646776#M676820</link>
      <description>James R. Ferguson&amp;gt;&amp;gt;&lt;BR /&gt;thanks much.&lt;BR /&gt;i will check it.&lt;BR /&gt;&lt;BR /&gt;is there a link for posix specifications for read/write/truncate/... system calls&lt;BR /&gt;&lt;BR /&gt;Scotty</description>
      <pubDate>Mon, 14 Jun 2010 12:02:59 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/does-file-truncate-affect-current-file-offset/m-p/4646776#M676820</guid>
      <dc:creator>Scotty HD</dc:creator>
      <dc:date>2010-06-14T12:02:59Z</dc:date>
    </item>
    <item>
      <title>Re: does file truncate affect current file offset</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/does-file-truncate-affect-current-file-offset/m-p/4646777#M676822</link>
      <description>&amp;gt;is there a link for posix specifications for read/write/truncate/... system calls&lt;BR /&gt;&lt;BR /&gt;I'm not sure.  But you should trust what's on truncate(2), since Integrity HP-UX 11.31 is Unix 2003 branded.</description>
      <pubDate>Mon, 14 Jun 2010 12:15:33 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/does-file-truncate-affect-current-file-offset/m-p/4646777#M676822</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2010-06-14T12:15:33Z</dc:date>
    </item>
    <item>
      <title>Re: does file truncate affect current file offset</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/does-file-truncate-affect-current-file-offset/m-p/4646778#M676825</link>
      <description>Hi (again) Scotty:&lt;BR /&gt;&lt;BR /&gt;&amp;gt; is there a link for posix specifications for read/write/truncate/... system calls&lt;BR /&gt;&lt;BR /&gt;I believe you will find what seek (no pun intended) here:&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://www.unix.org/version3/online.html" target="_blank"&gt;http://www.unix.org/version3/online.html&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Mon, 14 Jun 2010 12:47:15 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/does-file-truncate-affect-current-file-offset/m-p/4646778#M676825</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2010-06-14T12:47:15Z</dc:date>
    </item>
  </channel>
</rss>

