@@ -21,6 +21,12 @@ mergeInto(LibraryManager.library, {
21
21
: Math . pow ( 2 , bits ) + value ;
22
22
} ,
23
23
24
+ $strLen : function ( ptr ) {
25
+ var end = ptr ;
26
+ while ( HEAPU8 [ end ] ) ++ end ;
27
+ return end - ptr ;
28
+ } ,
29
+
24
30
// Converts a value we have as unsigned, into a signed value. For
25
31
// example, 200 in a uint8 would be a negative number.
26
32
$reSign : function ( value , bits ) {
@@ -46,7 +52,7 @@ mergeInto(LibraryManager.library, {
46
52
// varargs: A pointer to the start of the arguments list.
47
53
// Returns the resulting string string as a character array.
48
54
$formatString__deps : [ '$reallyNegative' , '$convertI32PairToI53' , '$convertU32PairToI53' ,
49
- '$reSign' , '$unSign' , 'strlen'
55
+ '$reSign' , '$unSign' , '$strLen' ,
50
56
#if MINIMAL_RUNTIME
51
57
, '$intArrayFromString'
52
58
#endif
@@ -409,7 +415,7 @@ mergeInto(LibraryManager.library, {
409
415
case 's' : {
410
416
// String.
411
417
var arg = getNextArg ( 'i8*' ) ;
412
- var argLength = arg ? _strlen ( arg ) : '( null ) '. length ;
418
+ var argLength = arg ? strLen ( arg ) : '( null ) '. length ;
413
419
if ( precisionSet ) argLength = Math . min ( argLength , precision ) ;
414
420
if ( ! flagLeftAlign ) {
415
421
while ( argLength < width -- ) {
@@ -467,37 +473,5 @@ mergeInto(LibraryManager.library, {
467
473
}
468
474
return ret ;
469
475
} ,
470
-
471
- // printf/puts/strlen implementations for when musl is not pulled in - very
472
- // partial. useful for tests, and when bootstrapping structInfo
473
- strlen : function ( ptr ) {
474
- { { { from64 ( 'ptr' ) } } } ;
475
- var end = ptr ;
476
- while ( HEAPU8 [ end ] ) ++ end ;
477
- return end - ptr ;
478
- } ,
479
- printf__deps : [ '$formatString'
480
- #if MINIMAL_RUNTIME
481
- , '$intArrayToString'
482
- #endif
483
- ] ,
484
- printf : function ( format , varargs ) {
485
- // int printf(const char *restrict format, ...);
486
- // http://pubs.opengroup.org/onlinepubs/000095399/functions/printf.html
487
- // extra effort to support printf, even without a filesystem. very partial, very hackish
488
- var result = formatString ( format , varargs ) ;
489
- var string = intArrayToString ( result ) ;
490
- if ( string [ string . length - 1 ] === '\n' ) string = string . substr ( 0 , string . length - 1 ) ; // remove a final \n, as Module.print will do that
491
- out ( string ) ;
492
- return result . length ;
493
- } ,
494
- puts : function ( s ) {
495
- // extra effort to support puts, even without a filesystem. very partial, very hackish
496
- var result = UTF8ToString ( s ) ;
497
- var string = result . substr ( 0 ) ;
498
- if ( string [ string . length - 1 ] === '\n' ) string = string . substr ( 0 , string . length - 1 ) ; // remove a final \n, as Module.print will do that
499
- out ( string ) ;
500
- return result . length ;
501
- } ,
502
476
} ) ;
503
477
0 commit comments