Disable nextmap in Synergy and Dystopia (
bug 3687,
bug 3741; r=liam)
3 * Routines to maintain a "text file" in memory.
5 * Copyright (c) ITB CompuPhase, 2003-2006
7 * This software is provided 'as-is', without any express or implied warranty.
8 * In no event will the authors be held liable for any damages arising from the
9 * use of this software.
11 * Permission is granted to anyone to use this software for any purpose,
12 * including commercial applications, and to alter it and redistribute it
13 * freely, subject to the following restrictions:
15 * 1. The origin of this software must not be misrepresented; you must not
16 * claim that you wrote the original software. If you use this software in
17 * a product, an acknowledgment in the product documentation would be
18 * appreciated but is not required.
20 * 2. Altered source versions must be plainly marked as such, and must not be
21 * misrepresented as being the original software.
23 * 3. This notice may not be removed or altered from any source distribution.
35 #include <alloc/fortify.h>
37 typedef memfile_t MEMFILE;
42 MEMFILE *mfcreate(const char *filename)
44 return memfile_creat(filename, 4096);
47 void mfclose(MEMFILE *mf)
52 int mfdump(MEMFILE *mf)
59 fp=fopen(mf->name, "wb");
64 okay = okay & (fwrite(mf->base, mf->usedoffs, 1, fp)==(size_t)mf->usedoffs);
70 long mflength(const MEMFILE *mf)
75 long mfseek(MEMFILE *mf,long offset,int whence)
80 if (mf->usedoffs == 0)
81 return 0L; /* early exit: not a single byte in the file */
83 /* find the size of the memory file */
86 /* convert the offset to an absolute position */
99 /* clamp to the file length limit */
102 else if (offset>length)
105 /* set new position and return it */
106 memfile_seek(mf, offset);
111 unsigned int mfwrite(MEMFILE *mf,const unsigned char *buffer,unsigned int size)
113 return (memfile_write(mf, buffer, size) ? size : 0);
116 unsigned int mfread(MEMFILE *mf,unsigned char *buffer,unsigned int size)
118 return memfile_read(mf, buffer, size);
121 char *mfgets(MEMFILE *mf,char *string,unsigned int size)
129 read=mfread(mf,(unsigned char *)string,size);
134 /* make sure that the string is zero-terminated */
140 seek=-1; /* undo reading the character that gets overwritten */
143 /* find the first '\n' */
144 ptr=strchr(string,'\n');
147 seek=(long)(ptr-string)+1-(long)read;
151 assert(seek<=0); /* should seek backward only */
153 mfseek(mf,seek,SEEK_CUR);
158 int mfputs(MEMFILE *mf,const char *string)
160 unsigned int written,length;
164 length=strlen(string);
165 written=mfwrite(mf,(unsigned char *)string,length);
166 return written==length;