TamiL
TamiL

Reputation: 2896

dos.h for Linux?

I have a C program which contains #include <dos.h> header. It shows a compile time error. I know that the dos.h header file is not valid in Linux.

Is there any other equivalent header for dos.h in Linux?

Upvotes: 6

Views: 27517

Answers (3)

Anas Karmoua
Anas Karmoua

Reputation: 1

#include<dos.h> is not available for Linux but if you want to use dos.h for displaying the time you can use the system function and do it like this

prototype -> system(command);

system("date +%H:%M:%S");

if you want your program to sleep for a specific seconds try this

system("sleep 3") //sleep for a 3 seconds

or use this

std::this_thread::sleep_for(std::chrono::milliseconds(100));

but you have to include the thread header file #include<thread>

Upvotes: 0

Linux is a Posix/Unix like system, so you should learn the system calls and facilities that you can use. Read the advanced unix programming book (or some equivalent; AUP is considered a very good book). You can also read advanced linux programming (even online, a copy is here). So Linux don't have a dos.h header.

You could also type man 2 intro to get an intro to syscalls, and their list in in syscalls(2) man page. From an application's point of view syscalls are elementary operations provided by the Linux kernel.

The GNU libc provides a big lot of functionality (e.g. standard C functions like malloc and fprintf, and system functions like fgetpwent to query user database, etc etc...) above the system calls. Almost every Linux program uses it.

If you care about coding stuff which should be portably runnable (after recompilation) on other similar systems (e.g. MacOSX or FreeBSD) consider following the Posix standard.

If you want to code a terminal screen application, consider using ncurses.

If you care about graphical interfaces, use a graphical toolkit like Qt or Gtk; they usually interact with an X11 server (and both Qt and Gtk are able to run on some other non Posix systems, e.g. Windows, by providing a common graphical abstraction layer.). Both Gtk and Qt are adding an abstraction layer (Glib and QCore respectively) above system functions and facilities (in particular above the pthreads standard thread library).

At last, Linux is free software; so you might find interesting to look inside the source code (of a library or utility) that you are using. You could even improve it and contribute to it.

In all these aspects, Linux programming is very different from Windows or DOS.

Don't try to mimic every Windows or Dos function into Linux (e.g. don't ask the equivalent of every dos.h function); learn the Posix/Unix way of thinking and coding.

The time(7) man page tells you a lot about time (various meanings and functions about it) on Linux.

Don't forget to ask warnings from the compiler with gcc -Wall -Wextra; as a general rule, improve your source code till you get no warnings.

There cannot be an exact Linux equivalent of dos.h because Linux (i.e. Unix or Posix spec) and Windows are systems with different features and concepts. However several free libraries (I mentioned Glib and QCore) are providing common abstractions to fit into Linux and into Windows, so if you want to develop software portable to Windows and to Linux I suggest using these libraries instead (use them both on Windows and on Linux).

(I also suspect that Microsoft would use legal threats -patent or copyright based- to avoid that free clone of their proprietary dos.h, given their monopolistic reputation and their aversion to standards and to free software; I admit I have strong opinions against Microsoft..)

Upvotes: 10

McLosys Creative
McLosys Creative

Reputation: 759

dos.h header file is interface to the DOS operating system. They are not portable to operating systems other than DOS (means not works in Linux). Which functionality in dos.h you are going to use?

Upvotes: 10

Related Questions