16 #include "mysys_priv.h"
17 #include "mysys_err.h"
40 int my_chsize(File fd, my_off_t newlength,
int filler, myf MyFlags)
44 DBUG_ENTER(
"my_chsize");
45 DBUG_PRINT(
"my",(
"fd: %d length: %lu MyFlags: %d",fd,(ulong) newlength,
48 if ((oldsize= my_seek(fd, 0L, MY_SEEK_END, MYF(MY_WME+MY_FAE))) == newlength)
51 DBUG_PRINT(
"info",(
"old_size: %ld", (ulong) oldsize));
53 if (oldsize > newlength)
56 if (my_win_chsize(fd, newlength))
62 #elif defined(HAVE_FTRUNCATE)
63 if (ftruncate(fd, (off_t) newlength))
69 #elif defined(HAVE_CHSIZE)
70 if (chsize(fd, (off_t) newlength))
81 if (my_seek(fd, newlength, MY_SEEK_SET, MYF(MY_WME+MY_FAE))
86 swap_variables(my_off_t, newlength, oldsize);
91 memset(buff, filler, IO_SIZE);
92 while (newlength-oldsize > IO_SIZE)
94 if (my_write(fd, buff, IO_SIZE, MYF(MY_NABP)))
98 if (my_write(fd,buff,(
size_t) (newlength-oldsize), MYF(MY_NABP)))
103 DBUG_PRINT(
"error", (
"errno: %d", errno));
104 if (MyFlags & MY_WME)
106 char errbuf[MYSYS_STRERROR_SIZE];
107 my_error(EE_CANT_CHSIZE, MYF(ME_BELL+ME_WAITTANG),
108 my_errno, my_strerror(errbuf,
sizeof(errbuf), my_errno));