hi, when i compile my c code at visual C++ 6.0, i got some errors and i can't fix it, please help..

my C file uses the unistd.h and the code is

/* This is defined as a real library function to allow autoconf
to verify its existence. */
int ftruncate(int, off_t);
__CRT_INLINE int ftruncate(int __fd, off_t __length)
{
return _chsize (__fd, __length);
}

errors:
error C2081: 'off_t' : name in formal parameter list illegal
error C2054: expected '(' to follow '__CRT_INLINE'
error C2146: syntax error : missing ')' before identifier '__length'
error C2081: 'off_t' : name in formal parameter list illegal
error C2082: redefinition of formal parameter 'ftruncate'
error C2146: syntax error : missing ',' before identifier '__length'
error C2059: syntax error : ')'
error C2143: syntax error : missing ';' before '{'

That compiler does not have unistd.h -- that is a *nix header file. There is no substitute for Windows.

what can i do?

>>what can i do?
If you are trying to port some program to MS-Windows you will have to rewrite parts or all of it. First determine what the function(s) is supposed to do then use win32 api functions or standard C functions to do it. MS-Windows does not support POSIX.

For example: ftruncate truncates a file to a specified length. The equivalent win32 api function is move the file pointer to the desired location then call SetEndOfFile() to truncate it.

The only header file you need for most win32 api functions is windows.h. If the function you need isn't in windows.h (such as the compiler complains that it can't find a function) then you have to look up that function in MSDN as www.microsoft.com and it will tell you what header files and libraries are needed.

>>what can i do?
If you are tring to port some program to MS-Windows you will have to rewrite parts or all of it. First determine what the function(s) is supposed to do then use win32 api functions or standard C functions to do it. MS-Windows does not support POSIX.

For example: ftruncate truncates a file to a specified length. The equivalent win32 api function is move the file pointer to the desired location then call SetEndOfFile() to truncate it.

thanks, is there any program that can compile it? it is impossible because of using MS-Windows?

Your best bet at getting Unix / Linux code to compile on a windows machine is to grab cygwin, then run the setup utility to get gcc, then compile your code.

This article has been dead for over six months. Start a new discussion instead.