comparison compat.c @ 557:1a210e2f214b

Added a bunch of support routines I now own due to the settlement agreement with F/X. Shared memory and named event semaphores in particular.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Sat, 17 Apr 2004 05:38:09 +0000
parents 469ff8133ed3
children d7c338ac926a
comparison
equal deleted inserted replaced
556:f4093dce8155 557:1a210e2f214b
709 } 709 }
710 710
711 int API fsseek(FILE *stream, long offset, int whence) 711 int API fsseek(FILE *stream, long offset, int whence)
712 { 712 {
713 return fseek(stream, offset, whence); 713 return fseek(stream, offset, whence);
714 }
715
716 void API nice_strformat(char *dest, long double val, int dec)
717 {
718 char formatbuf[10];
719 char format = 0;
720 double printval;
721
722 /* 1024 ^ 3 = Gigabytes */
723 if(val >= 1073741824L)
724 {
725 printval = val/(1073741824L);
726 format = 'G';
727 }
728 /* 1024 ^ 2 = Megabytes */
729 else if(val >= 1048576)
730 {
731 printval = val/(1048576);
732 format = 'M';
733 }
734 /* 1024 = Kilobytes */
735 else if(val > 1024)
736 {
737 printval = val/1024;
738 format = 'K';
739 }
740 else
741 printval = val;
742
743 /* Generate the format string */
744 sprintf(formatbuf, "%%.%df%c", dec, format);
745 /* Create the pretty value */
746 sprintf(dest, formatbuf, printval);
747 }
748
749 /* Update the current working directory based on the
750 * path of the executable being executed.
751 */
752 void API initdir(int argc, char *argv[])
753 {
754 if(argc > 0)
755 {
756 char *tmpdir = strdup(argv[0]);
757 int z, len = strlen(argv[0]);
758
759 for(z=len;z > -1;z--)
760 {
761 if(tmpdir[z] == '/')
762 {
763 tmpdir[z+1] = 0;
764 setpath(tmpdir);
765 free(tmpdir);
766 return;
767 }
768 }
769 free(tmpdir);
770 }
771 }
772
773 /*
774 * Sets the current directory (and drive) information.
775 * Parameters:
776 * path: A buffer containing the new path.
777 * Returns:
778 * -1 on error.
779 */
780 int API setpath(char *path)
781 {
782 #if defined(__OS2__) || defined(__WIN32__)
783 if(strlen(path) > 2)
784 {
785 if(path[1] == ':')
786 {
787 char drive = toupper(path[0]);
788 _chdrive((drive - 'A')+1);
789 }
790 }
791 #endif
792 return chdir(path);
714 } 793 }
715 794
716 static int locale_number = -1, locale_count = 0; 795 static int locale_number = -1, locale_count = 0;
717 static char **locale_text = NULL; 796 static char **locale_text = NULL;
718 797