home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / snip9707.zip / DOSFRMAT.C < prev    next >
C/C++ Source or Header  |  1997-07-05  |  1KB  |  61 lines

  1. /* +++Date last modified: 05-Jul-1997 */
  2.  
  3. /*
  4. **  FORMAT.C - Use DOS FORMAT to format a diskette
  5. **
  6. **  Original Copyright 1992 by Bob Stout as part of
  7. **  the MicroFirm Function Library (MFL)
  8. **
  9. **  The user is granted a free limited license to use this source file
  10. **  to create royalty-free programs, subject to the terms of the
  11. **  license restrictions specified in the LICENSE.MFL file.
  12. */
  13.  
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include "snpdosys.h"
  17.  
  18. /*
  19. **  format
  20. **
  21. **  Formats a specified floppy disk with optional switches.
  22. **
  23. **  Parameters: 1 - Drive letter ('A', 'B', ...) to format
  24. **              2 - Formatting switches in FORMAT.COM format, e.g. "/4"
  25. **              3 - Volume label
  26. **
  27. **  Returns: Success_ or Error_
  28. */
  29.  
  30. int format(char drive, char *switches, char *vlabel)
  31. {
  32.       char command[128], fname[13];
  33.       FILE *tmpfile;
  34.  
  35.       tmpnam(fname);
  36.       if (NULL == (tmpfile = fopen(fname, "w")))
  37.             return Error_;                       /* Can't open temp file */
  38.       fprintf(tmpfile, "\n%s\nN\n", vlabel);
  39.       fclose(tmpfile);
  40.  
  41.       sprintf(command, "format %c: /V %s < %s > NUL", drive, switches, fname);
  42.  
  43.       system(command);
  44.  
  45.       remove(fname);
  46.  
  47.       return Success_;
  48. }
  49.  
  50. #ifdef TEST
  51.  
  52. main()
  53. {
  54.       int retval = format((char)'a', "/4", "dummy_test");
  55.  
  56.       printf("format() returned %d\n", retval);
  57.       return 0;
  58. }
  59.  
  60. #endif /* TEST */
  61.