Home | History | Annotate | Download | only in test
      1 /*
      2  *  Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
      3  *
      4  *  Use of this source code is governed by a BSD-style license
      5  *  that can be found in the LICENSE file in the root of the source
      6  *  tree. An additional intellectual property rights grant can be found
      7  *  in the file PATENTS.  All contributing project authors may
      8  *  be found in the AUTHORS file in the root of the source tree.
      9  */
     10 
     11 #include "dl/sp/src/test/aligned_ptr.h"
     12 
     13 #include <stdlib.h>
     14 
     15 /* |alignment| is the byte alignment and MUST be a power of two. */
     16 struct AlignedPtr* AllocAlignedPointer(int alignment, int bytes) {
     17   struct AlignedPtr* aligned_ptr;
     18   unsigned long raw_address;
     19 
     20   aligned_ptr = (struct AlignedPtr*) malloc(sizeof(*aligned_ptr));
     21   aligned_ptr->raw_pointer_ = malloc(bytes + alignment);
     22   raw_address = (unsigned long) aligned_ptr->raw_pointer_;
     23   raw_address = (raw_address + alignment - 1) & ~(alignment - 1);
     24   aligned_ptr->aligned_pointer_ = (void*) raw_address;
     25 
     26   return aligned_ptr;
     27 }
     28 
     29 void FreeAlignedPointer(struct AlignedPtr* pointer) {
     30   free(pointer->raw_pointer_);
     31   free(pointer);
     32 }
     33