Changeset 102223 in vbox for trunk/src/libs/xpcom18a4/nsprpub
- Timestamp:
- Nov 21, 2023 9:42:06 PM (14 months ago)
- Location:
- trunk/src/libs/xpcom18a4/nsprpub/pr
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/libs/xpcom18a4/nsprpub/pr/include/prprf.h
r102194 r102223 64 64 #define PR_smprintf VBoxNsprPR_smprintf 65 65 #define PR_smprintf_free VBoxNsprPR_smprintf_free 66 #define PR_sprintf_append VBoxNsprPR_sprintf_append67 #define PR_sxprintf VBoxNsprPR_sxprintf68 66 #define PR_vsmprintf VBoxNsprPR_vsmprintf 69 #define PR_vsprintf_append VBoxNsprPR_vsprintf_append70 #define PR_vsxprintf VBoxNsprPR_vsxprintf71 67 #endif /* VBOX_WITH_XPCOM_NAMESPACE_CLEANUP */ 72 68 … … 93 89 94 90 /* 95 ** "append" sprintf into a PR_MALLOC'd buffer. "last" is the last value of96 ** the PR_MALLOC'd buffer. sprintf will append data to the end of last,97 ** growing it as necessary using realloc. If last is NULL, PR_sprintf_append98 ** will allocate the initial string. The return value is the new value of99 ** last for subsequent calls, or NULL if there is a malloc failure.100 */101 NSPR_API(char*) PR_sprintf_append(char *last, const char *fmt, ...);102 103 /*104 ** sprintf into a function. The function "f" is called with a string to105 ** place into the output. "arg" is an opaque pointer used by the stuff106 ** function to hold any state needed to do the storage of the output107 ** data. The return value is a count of the number of characters fed to108 ** the stuff function, or (PRUint32)-1 if an error occurs.109 */110 typedef PRIntn (*PRStuffFunc)(void *arg, const char *s, PRUint32 slen);111 112 NSPR_API(PRUint32) PR_sxprintf(PRStuffFunc f, void *arg, const char *fmt, ...);113 114 /*115 91 ** va_list forms of the above. 116 92 */ 117 93 NSPR_API(PRUint32) PR_vsnprintf(char *out, PRUint32 outlen, const char *fmt, va_list ap); 118 94 NSPR_API(char*) PR_vsmprintf(const char *fmt, va_list ap); 119 NSPR_API(char*) PR_vsprintf_append(char *last, const char *fmt, va_list ap);120 NSPR_API(PRUint32) PR_vsxprintf(PRStuffFunc f, void *arg, const char *fmt, va_list ap);121 95 122 96 PR_END_EXTERN_C -
trunk/src/libs/xpcom18a4/nsprpub/pr/include/prtime.h
r102178 r102223 53 53 #ifdef VBOX_WITH_XPCOM_NAMESPACE_CLEANUP 54 54 #define PR_Now VBoxNsprPR_Now 55 #define PR_ExplodeTime VBoxNsprPR_ExplodeTime56 #define PR_ImplodeTime VBoxNsprPR_ImplodeTime57 #define PR_NormalizeTime VBoxNsprPR_NormalizeTime58 55 #endif /* VBOX_WITH_XPCOM_NAMESPACE_CLEANUP */ 59 56 … … 87 84 typedef PRInt64 PRTime; 88 85 89 /*90 * Time zone and daylight saving time corrections applied to GMT to91 * obtain the local time of some geographic location92 */93 94 typedef struct PRTimeParameters {95 PRInt32 tp_gmt_offset; /* the offset from GMT in seconds */96 PRInt32 tp_dst_offset; /* contribution of DST in seconds */97 } PRTimeParameters;98 99 /*100 * PRExplodedTime --101 *102 * Time broken down into human-readable components such as year, month,103 * day, hour, minute, second, and microsecond. Time zone and daylight104 * saving time corrections may be applied. If they are applied, the105 * offsets from the GMT must be saved in the 'tm_params' field so that106 * all the information is available to reconstruct GMT.107 *108 * Notes on porting: PRExplodedTime corrresponds to struct tm in109 * ANSI C, with the following differences:110 * - an additional field tm_usec;111 * - replacing tm_isdst by tm_params;112 * - the month field is spelled tm_month, not tm_mon;113 * - we use absolute year, AD, not the year since 1900.114 * The corresponding type in NSPR 1.0 is called PRTime. Below is115 * a table of date/time type correspondence in the three APIs:116 * API time since epoch time in components117 * ANSI C time_t struct tm118 * NSPR 1.0 PRInt64 PRTime119 * NSPR 2.0 PRTime PRExplodedTime120 */121 122 typedef struct PRExplodedTime {123 PRInt32 tm_usec; /* microseconds past tm_sec (0-99999) */124 PRInt32 tm_sec; /* seconds past tm_min (0-61, accomodating125 up to two leap seconds) */126 PRInt32 tm_min; /* minutes past tm_hour (0-59) */127 PRInt32 tm_hour; /* hours past tm_day (0-23) */128 PRInt32 tm_mday; /* days past tm_mon (1-31, note that it129 starts from 1) */130 PRInt32 tm_month; /* months past tm_year (0-11, Jan = 0) */131 PRInt16 tm_year; /* absolute year, AD (note that we do not132 count from 1900) */133 134 PRInt8 tm_wday; /* calculated day of the week135 (0-6, Sun = 0) */136 PRInt16 tm_yday; /* calculated day of the year137 (0-365, Jan 1 = 0) */138 139 PRTimeParameters tm_params; /* time parameters used by conversion */140 } PRExplodedTime;141 142 /*143 * PRTimeParamFn --144 *145 * A function of PRTimeParamFn type returns the time zone and146 * daylight saving time corrections for some geographic location,147 * given the current time in GMT. The input argument gmt should148 * point to a PRExplodedTime that is in GMT, i.e., whose149 * tm_params contains all 0's.150 *151 * For any time zone other than GMT, the computation is intended to152 * consist of two steps:153 * - Figure out the time zone correction, tp_gmt_offset. This number154 * usually depends on the geographic location only. But it may155 * also depend on the current time. For example, all of China156 * is one time zone right now. But this situation may change157 * in the future.158 * - Figure out the daylight saving time correction, tp_dst_offset.159 * This number depends on both the geographic location and the160 * current time. Most of the DST rules are expressed in local161 * current time. If so, one should apply the time zone correction162 * to GMT before applying the DST rules.163 */164 165 typedef PRTimeParameters (PR_CALLBACK *PRTimeParamFn)(const PRExplodedTime *gmt);166 167 86 /**********************************************************************/ 168 87 /****************************** FUNCTIONS *****************************/ … … 189 108 PR_Now(void); 190 109 191 /*192 * Expand time binding it to time parameters provided by PRTimeParamFn.193 * The calculation is envisoned to proceed in the following steps:194 * - From given PRTime, calculate PRExplodedTime in GMT195 * - Apply the given PRTimeParamFn to the GMT that we just calculated196 * to obtain PRTimeParameters.197 * - Add the PRTimeParameters offsets to GMT to get the local time198 * as PRExplodedTime.199 */200 201 NSPR_API(void) PR_ExplodeTime(202 PRTime usecs, PRTimeParamFn params, PRExplodedTime *exploded);203 204 /* Reverse operation of PR_ExplodeTime */205 #if defined(HAVE_WATCOM_BUG_2)206 PRTime __pascal __export __loadds207 #else208 NSPR_API(PRTime)209 #endif210 PR_ImplodeTime(const PRExplodedTime *exploded);211 212 /*213 * Adjust exploded time to normalize field overflows after manipulation.214 * Note that the following fields of PRExplodedTime should not be215 * manipulated:216 * - tm_month and tm_year: because the number of days in a month and217 * number of days in a year are not constant, it is ambiguous to218 * manipulate the month and year fields, although one may be tempted219 * to. For example, what does "a month from January 31st" mean?220 * - tm_wday and tm_yday: these fields are calculated by NSPR. Users221 * should treat them as "read-only".222 */223 224 NSPR_API(void) PR_NormalizeTime(225 PRExplodedTime *exploded, PRTimeParamFn params);226 227 110 PR_END_EXTERN_C 228 111 -
trunk/src/libs/xpcom18a4/nsprpub/pr/src/io/prprf.c
r102000 r102223 1012 1012 } 1013 1013 1014 /************************************************************************/1015 1016 static int FuncStuff(SprintfState *ss, const char *sp, PRUint32 len)1017 {1018 int rv;1019 1020 rv = (*ss->func)(ss->arg, sp, len);1021 if (rv < 0) {1022 return rv;1023 }1024 ss->maxlen += len;1025 return 0;1026 }1027 1028 PR_IMPLEMENT(PRUint32) PR_sxprintf(PRStuffFunc func, void *arg,1029 const char *fmt, ...)1030 {1031 va_list ap;1032 PRUint32 rv;1033 1034 va_start(ap, fmt);1035 rv = PR_vsxprintf(func, arg, fmt, ap);1036 va_end(ap);1037 return rv;1038 }1039 1040 PR_IMPLEMENT(PRUint32) PR_vsxprintf(PRStuffFunc func, void *arg,1041 const char *fmt, va_list ap)1042 {1043 SprintfState ss;1044 int rv;1045 1046 ss.stuff = FuncStuff;1047 ss.func = func;1048 ss.arg = arg;1049 ss.maxlen = 0;1050 rv = dosprintf(&ss, fmt, ap);1051 return (rv < 0) ? (PRUint32)-1 : ss.maxlen;1052 }1053 1054 1014 /* 1055 1015 ** Stuff routine that automatically grows the malloc'd output buffer … … 1191 1151 return n ? n - 1 : n; 1192 1152 } 1193 1194 PR_IMPLEMENT(char *) PR_sprintf_append(char *last, const char *fmt, ...)1195 {1196 va_list ap;1197 char *rv;1198 1199 va_start(ap, fmt);1200 rv = PR_vsprintf_append(last, fmt, ap);1201 va_end(ap);1202 return rv;1203 }1204 1205 PR_IMPLEMENT(char *) PR_vsprintf_append(char *last, const char *fmt, va_list ap)1206 {1207 SprintfState ss;1208 int rv;1209 1210 ss.stuff = GrowStuff;1211 if (last) {1212 int lastlen = strlen(last);1213 ss.base = last;1214 ss.cur = last + lastlen;1215 ss.maxlen = lastlen;1216 } else {1217 ss.base = 0;1218 ss.cur = 0;1219 ss.maxlen = 0;1220 }1221 rv = dosprintf(&ss, fmt, ap);1222 if (rv < 0) {1223 if (ss.base) {1224 PR_DELETE(ss.base);1225 }1226 return 0;1227 }1228 return ss.base;1229 }1230
Note:
See TracChangeset
for help on using the changeset viewer.