Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Annotation of /sml/trunk/src/runtime/c-libs/smlnj-date/strftime.c
ViewVC logotype

Annotation of /sml/trunk/src/runtime/c-libs/smlnj-date/strftime.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 651 - (view) (download) (as text)

1 : monnier 249 /* strftime.c
2 :     *
3 :     * COPYRIGHT (c) 1996 AT&T Research.
4 :     */
5 :    
6 :     #include <time.h>
7 : blume 569 #include <string.h>
8 : monnier 249 #include "ml-base.h"
9 :     #include "ml-values.h"
10 :     #include "ml-objects.h"
11 :     #include "ml-c.h"
12 :     #include "cfun-proto-list.h"
13 :    
14 :     /* _ml_Date_strftime :
15 :     * (string * (int * int * int * int * int * int * int * int * int)) -> string
16 :     *
17 :     * This takes a format field and nine integer fields (sec, min, hour, mday, mon,
18 :     * year, wday, yday, and isdst), and converts it into a string representation
19 :     * according to the format string.
20 :     */
21 :     ml_val_t _ml_Date_strftime (ml_state_t *msp, ml_val_t arg)
22 :     {
23 :     ml_val_t fmt = REC_SEL(arg, 0);
24 :     ml_val_t res, date;
25 :     struct tm tm;
26 :     char buf[512];
27 :     size_t sz;
28 :    
29 :     date = REC_SEL(arg, 1);
30 :     tm.tm_sec = REC_SELINT(date, 0);
31 :     tm.tm_min = REC_SELINT(date, 1);
32 :     tm.tm_hour = REC_SELINT(date, 2);
33 :     tm.tm_mday = REC_SELINT(date, 3);
34 :     tm.tm_mon = REC_SELINT(date, 4);
35 :     tm.tm_year = REC_SELINT(date, 5);
36 :     tm.tm_wday = REC_SELINT(date, 6);
37 :     tm.tm_yday = REC_SELINT(date, 7);
38 :     tm.tm_isdst = REC_SELINT(date, 8);
39 :    
40 :     sz = strftime (buf, sizeof(buf), STR_MLtoC(fmt), &tm);
41 :     if (sz > 0) {
42 :     res = ML_AllocString(msp, sz);
43 :     strncpy (STR_MLtoC(res), buf, sz);
44 :     return res;
45 :     }
46 :     else
47 :     return RAISE_ERROR(msp, "strftime failed");
48 :    
49 :     } /* end of _ml_Date_strftime */
50 :    

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0