Nife version Beta
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

83 lines
1.7 KiB

  1. /* Copyright (C) 2011-2014 Patrick H. E. Foubet - S.E.R.I.A.N.E.
  2. This program is free software: you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License as published by
  4. the Free Software Foundation, either version 3 of the License, or any
  5. later version.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. GNU General Public License for more details.
  10. You should have received a copy of the GNU General Public License
  11. along with this program. If not, see <http://www.gnu.org/licenses/>
  12. *******************************************************************/
  13. /* debug.c */
  14. #include "conf.h"
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #include <unistd.h>
  18. #include <string.h>
  19. #include <sys/types.h>
  20. #include <sys/stat.h>
  21. #include <fcntl.h>
  22. #include "nife.h"
  23. #include "mth.h"
  24. #include "debug.h"
  25. int Debug=1; /* OK by default */
  26. void D_Reset(void)
  27. {
  28. int fd;
  29. char NF[24];
  30. chdir(".nife");
  31. if (Debug) {
  32. sprintf(NF,".nife_%d.log",getpid());
  33. if ((fd=open(NF,O_CREAT|O_RDWR|O_TRUNC,0644)) < 0) perror(NF);
  34. else {
  35. dup2(fd,2);
  36. close(fd);
  37. }
  38. } else dup2(1,2);
  39. chdir("..");
  40. }
  41. void D_Update(void)
  42. {
  43. if (Debug) Debug=0;
  44. else Debug=1;
  45. D_Reset();
  46. }
  47. void D_Trace(char * M)
  48. {
  49. if (Debug) {
  50. fprintf(stderr," %s",M);
  51. fflush(stderr);
  52. }
  53. }
  54. static char D_Mes[20];
  55. void * Malloc(int s)
  56. {
  57. void * M;
  58. D_Trace("\n");
  59. M=malloc(s);
  60. sprintf(D_Mes,"Malloc %d : %lx\n",s,(long)M);
  61. D_Trace(D_Mes);
  62. return M;
  63. }
  64. void Free(void *A)
  65. {
  66. D_Trace("\n");
  67. sprintf(D_Mes,"Free : %lx\n",(long)A);
  68. D_Trace(D_Mes);
  69. free(A);
  70. }