The Standard C Library: When to Use It for File Processing
Despite Windows' unique features, it is still possible to achieve most file processing (the subject of Chapters 2 and 3) by using the familiar C programming language and its ANSI Standard C library. The C library (the adjectives ANSI and Standard are often omitted) also contains numerous indispensable functions that do not correspond to Windows system calls, such as <string.h>, <stdlib.h>, <signal.h>, formatted I/O functions, and character I/O functions. Other functions, however, correspond closely to system calls, such as the fopen and fread functions in <stdio.h>.When is the C library adequate, and when is it necessary to use native Windows file management system calls? This same question could be asked about using C++ I/O streams or the system I/O provided within .NET. There is no easy answer, but portability to non-Windows platforms is a consideration in favor of the C library or C++ I/O streams if an application needs only file processing and not, for example, process management or other Windows capabilities. However, many programmers have formulated guidelines as to when the C library is or is not adequate, and these same guidelines should apply to Windows. In addition, given the increased power, performance potential, and flexibility provided by Windows, it is often convenient or even necessary to go beyond the C library, as we will see starting as early as Chapter 3. Windows file processing features not available with the C library include file locking, memory mapping (required for memory sharing), asynchronous I/O, random access to very long files (more than 4GB in length), and interprocess communication.The C library file management functions are often adequate for simple programs. With the C library, it is possible to write portable applications without learning Windows, but options will be limited. For example, Chapter 5 exploits memory-mapped files for performance and programming convenience, and this functionality is not included in the C library.