mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-05 02:38:31 +00:00
Refactor some code
- Write tests for cthreads - Fix bugs in pe2.com tool - Fix ASAN issue with GetDosEnviron() - Consolidate the cthread header files - Some code size optimizations for MODE= - Attempted to squash a tls linker warning - Attempted to get futexes working on FreeBSD
This commit is contained in:
parent
909e54510d
commit
425ff5dff0
61 changed files with 529 additions and 382 deletions
|
@ -21,11 +21,15 @@
|
|||
|
||||
/**
|
||||
* Returns file descriptor associated with stream.
|
||||
*
|
||||
* @param f is file stream object pointer
|
||||
* @return fd on success or -1 w/ errno;
|
||||
* @threadsafe
|
||||
*/
|
||||
int fileno_unlocked(FILE *f) {
|
||||
if (f->fd != -1) {
|
||||
return f->fd;
|
||||
} else {
|
||||
return ebadf();
|
||||
}
|
||||
int fileno(FILE *f) {
|
||||
int rc;
|
||||
flockfile(f);
|
||||
rc = fileno_unlocked(f);
|
||||
funlockfile(f);
|
||||
return rc;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
|
||||
│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│
|
||||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=8 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2020 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
|
@ -16,14 +16,19 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
|
||||
// Returns file descriptor associated with stream.
|
||||
//
|
||||
// @param rdi has file stream object pointer
|
||||
// @see fileno_unlocked()
|
||||
// @threadsafe
|
||||
fileno: mov %rdi,%r11
|
||||
ezlea fileno_unlocked,ax
|
||||
jmp stdio_unlock
|
||||
.endfn fileno,globl
|
||||
/**
|
||||
* Returns file descriptor associated with stream.
|
||||
*
|
||||
* @param f is file stream object pointer
|
||||
* @return fd on success or -1 w/ errno;
|
||||
*/
|
||||
int fileno_unlocked(FILE *f) {
|
||||
if (f->fd != -1) {
|
||||
return f->fd;
|
||||
} else {
|
||||
return ebadf();
|
||||
}
|
||||
}
|
|
@ -16,7 +16,6 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
|
||||
/**
|
||||
|
@ -24,15 +23,12 @@
|
|||
*
|
||||
* @param c is byte to buffer or write, which is masked
|
||||
* @return c as unsigned char if written or -1 w/ errno
|
||||
* @threadsafe
|
||||
*/
|
||||
int fputc_unlocked(int c, FILE *f) {
|
||||
unsigned char b;
|
||||
if (c != '\n' && f->beg < f->size && f->bufmode != _IONBF) {
|
||||
f->buf[f->beg++] = c;
|
||||
return c & 255;
|
||||
} else {
|
||||
b = c;
|
||||
if (!fwrite_unlocked(&b, 1, 1, f)) return -1;
|
||||
return b;
|
||||
}
|
||||
int fputc(int c, FILE *f) {
|
||||
int rc;
|
||||
flockfile(f);
|
||||
rc = fputc_unlocked(c, f);
|
||||
funlockfile(f);
|
||||
return rc;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
|
||||
│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│
|
||||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=8 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2020 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
|
@ -16,16 +16,23 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
|
||||
// Writes character to stream.
|
||||
//
|
||||
// @param rdi c is byte to buffer or write, which is masked
|
||||
// @param rsi has stream object pointer
|
||||
// @return c as unsigned char if written or -1 w/ errno
|
||||
// @see fputc_unlocked()
|
||||
// @threadsafe
|
||||
fputc: mov %rsi,%r11
|
||||
ezlea fputc_unlocked,ax
|
||||
jmp stdio_unlock
|
||||
.endfn fputc,globl
|
||||
/**
|
||||
* Writes byte to stream.
|
||||
*
|
||||
* @param c is byte to buffer or write, which is masked
|
||||
* @return c as unsigned char if written or -1 w/ errno
|
||||
*/
|
||||
int fputc_unlocked(int c, FILE *f) {
|
||||
unsigned char b;
|
||||
if (c != '\n' && f->beg < f->size && f->bufmode != _IONBF) {
|
||||
f->buf[f->beg++] = c;
|
||||
return c & 255;
|
||||
} else {
|
||||
b = c;
|
||||
if (!fwrite_unlocked(&b, 1, 1, f)) return -1;
|
||||
return b;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue