Ignore:
Timestamp:
Sep 25, 2007, 8:16:26 AM (18 years ago)
Author:
bird
Message:

Added as $(file-size ) function while at it.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kmk/function.c

    r1121 r1122  
    4343#include <assert.h> /* bird */
    4444
    45 #if defined (CONFIG_WITH_MATH) || defined (CONFIG_WITH_NANOTS) /* bird */
     45#if defined (CONFIG_WITH_MATH) || defined (CONFIG_WITH_NANOTS) || defined (CONFIG_WITH_FILE_SIZE) /* bird */
    4646# include <ctype.h>
    4747# ifdef _MSC_VER
     
    5151typedef int64_t math_int;
    5252# endif
     53static char *math_int_to_variable_buffer (char *, math_int);
    5354#endif
    5455
     
    26742675
    26752676#ifdef CONFIG_WITH_DATE
     2677/* The first argument is the strftime format string, a iso
     2678   timestamp is the default if nothing is given.
     2679
     2680   The second argument is a time value if given. The format
     2681   is either the format from the first argument or given as
     2682   an additional third argument. */
    26762683static char *
    26772684func_date (char *o, char **argv, const char *funcname)
     
    26892696        buf++;
    26902697      if (*buf)
    2691         format = buf;
     2698        format = argv[0];
    26922699    }
    26932700
     
    27092716  free (buf);
    27102717  return o;
     2718}
     2719#endif
     2720
     2721#ifdef CONFIG_WITH_FILE_SIZE
     2722/* Prints the size of the specified file. Only one file is
     2723   permitted, notthing is stripped. -1 is returned if stat
     2724   fails. */
     2725static char *
     2726func_file_size (char *o, char **argv, const char *funcname)
     2727{
     2728  struct stat st;
     2729  if (stat (argv[0], &st))
     2730    return variable_buffer_output (o, "-1", 2);
     2731  return math_int_to_variable_buffer (o, st.st_size);
    27112732}
    27122733#endif
     
    27622783#endif /* CONFIG_WITH_STACK */
    27632784
    2764 #if defined (CONFIG_WITH_MATH) || defined (CONFIG_WITH_NANOTS)
     2785#if defined (CONFIG_WITH_MATH) || defined (CONFIG_WITH_NANOTS) || defined (CONFIG_WITH_FILE_SIZE)
    27652786/* outputs the number (as a string) into the variable buffer. */
    27662787static char *
     
    31963217  { STRING_SIZE_TUPLE("date-utc"),      0,  1,  1,  func_date},
    31973218#endif
     3219#ifdef CONFIG_WITH_FILE_SIZE
     3220  { STRING_SIZE_TUPLE("file-size"),     1,  1,  1,  func_file_size},
     3221#endif
    31983222#ifdef CONFIG_WITH_STACK
    31993223  { STRING_SIZE_TUPLE("stack-push"),    2,  2,  1,  func_stack_push},
Note: See TracChangeset for help on using the changeset viewer.